美丽的照片!: http://www.beautifulphoto.net/
如下代码:
导入 urllib2
导入重新
_random_url = r'http://www.beautifulphoto.net/plugin/RndArticle/'
_img_patt = re.compile(r'')
def random(timeout=3, more=False):
尝试:
html = urllib2.urlopen(_random_url, timeout=timeout).read()
除了 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' % 名称, '%s.jpg' % 名称
return 'http://www.beautifulphoto.net/upload/%s_mini.jpg' % 名称
返回无
if __name__ == '__main__':
url = random()
print(url)
if url:
import webbrowser as wb
wb.open(url)