代码如下:
import urllib2
import re
_random_url = r'http://HdhCmsTestbeautifulphoto.net/plugin/RndArticle/'
_img_patt = re测试数据pile(r' ')
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://HdhCmsTestbeautifulphoto.net/upload/', '%s_mini.jpg' % name, '%s.jpg' % name
return 'http://HdhCmsTestbeautifulphoto.net/upload/%s_mini.jpg' % name
return None
if __name__ == '__main__':
url = random()
print(url)
if url:
import webbrowser as wb
wb.open(url)
查看更多关于python获取beautifulphoto随机某图片代码实例的详细内容...