当前位置: 移动技术网 > IT编程>脚本编程>Python > python获取beautifulphoto随机某图片代码实例

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

2019年04月02日  | 移动技术网IT编程  | 我要评论

麻辣博士谈军事,海神谜咒套,外交部提醒暂勿赴菲

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)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网