源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-06-20 13:47 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:python获取beautifulphoto随机某图片代码实例
Beautiful Photo!: http://www.beautifulphoto.net/
[u]复制代码[/u] 代码如下:
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)
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部