1,pythonzhuaqu/ target=_blank class=infotextkey>python抓取网页中图片。
#coding:utf8
import re
import urllib
def getHTML(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html,imgType):
reg = r'src="(.*?.+'+imgType+'!slider)" '
imgre = re.compile(reg)
imgList = re.findall(imgre, html)
x=0
for imgurl in imgList:
print imgurl
urllib.urlretrieve(imgurl, '%s.%s' % (x, imgType))
x =x+1
html= getHTML("http://www.jb200.com")
getImg(html,'jpg')
2,python抓取网页内容
python抓取网页内容示例,在抓取时对于gbk编码网页需要做好编码转换。