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 getImg(html,'jpg')
相关推荐
andrewwf 2020-11-11
AI启蒙研究院 2020-10-23
kkkmmmjjjj 2020-10-22
huang00 2020-10-12
Safari浏览器 2020-01-18
登峰小蚁 2020-01-11
chouliqingke 2019-12-17
haocxy 2013-12-12
Batkid0 2015-03-04
javaraylu 2012-06-19
YichengGu 2010-12-21
greatking 2010-07-22
小方哥哥 2019-07-01
aikaibo 2013-04-05
fangjack 2012-02-01
凌云客 2019-06-27