本文实例讲述了Python使用正则表达式抓取网页图片的方法。分享给大家供大家参考,具体如下:
#!/usr/bin/python import re import urllib #获取网页信息 def getHtml(url): page = urllib.urlopen(url) html = page.read() return html def getImg(html): #匹配网页中的图片 reg = r'src="(.*?\.jpg)" alt' imgre = re测试数据pile(reg) imglist = re.findall(imgre,html) x = 0 for imgurl in imglist: urllib.urlretrieve(imgurl,'%s.jpg' % x) x+=1 html = getHtml("http://photo.bitauto测试数据/?WT.mc_id=360tpdq") print getImg(html)
以上就是使用正则表达式抓取网页图片的Python代码实例的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于使用正则表达式抓取网页图片的Python代码实例的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did85146