好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

使用正则表达式抓取网页图片的Python代码实例

这篇文章主要介绍了Python使用正则表达式抓取网页图片的方法,结合具体实例形式分析了Python网页文件的读取及正则匹配相关操作技巧,需要的朋友可以参考下

本文实例讲述了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代码实例的详细内容...

  阅读:49次