这篇文章主要介绍了python抓取网页中图片的示例,需要的朋友可以参考下
代码如下:
#coding:utf8
import re
import urllib
def getHTML(url):
page = urllib.urlopen(url)
html来源gaodaimacom搞#^代%!码&网 = page.read()
return html
import re
import urllib
def getHTML(url):
page = urllib.urlopen(url)
html来源gaodaimacom搞#^代%!码&网 = 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(“https://www.gaodaima.com”
getImg(html,’jpg’)
以上就是python抓取网页中的图片示例的详细内容,更多请关注gaodaima搞代码网其它相关文章!