当前位置 博文首页 > python获取beautifulphoto随机某图片代码实例

    python获取beautifulphoto随机某图片代码实例

    作者:admin 时间:2021-02-20 06:42

    Beautiful Photo!: http://www.beautifulphoto.net/

    复制代码 代码如下:

    import urllib2
    import re

    _random_url = r'http://www.beautifulphoto.net/plugin/RndArticle/'
    _img_patt = re.compile(r'<img src="http://www\.beautifulphoto\.net/upload/(\d+)\.jpg" />')

    def random(timeout=3, more=False):
        try:
            html = urllib2.urlopen(_random_url, timeout=timeout).read()
        except urllib2.URLError, e:
            return None
        res = re.search(_img_patt, html)
        if res:
            name = res.group(1)
            if more:
                return 'http://www.beautifulphoto.net/upload/', '%s_mini.jpg' % name, '%s.jpg' % name
            return 'http://www.beautifulphoto.net/upload/%s_mini.jpg' % name
        return None

    if __name__ == '__main__':
        url = random()
        print(url)
        if url:
            import webbrowser as wb
            wb.open(url)

    js
    下一篇:没有了