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 Noneif __name__ == '__main__':
url = random()
print(url)
if url:
import webbrowser as wb
wb.open(url)
以上就是python获取beautifulphoto随机某图片代码实例。前尘如故地唯美白雪,芳时明月,空悲切,终离别。更多关于python获取beautifulphoto随机某图片代码实例请关注haodaima.com其它相关文章!