Python 2.7爬虫爬取图片,为什么不能下载到本地?
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
import urllib
def getHtml(url):
response=urllib.urlopen(url)
html=response.read()
return html
def getImg(html):
reg=r'src="(.+?\.png)" alt'
# re.compile() 可以把正则表达式编译成一个正则表达式对象
imgre=re.compile(reg)
# re.findall() 方法读取html 中包含 imgre(正则表达式)的数据
imglist=re.findall(imgre,html)
i=0
for img in imglist:
urllib.urlretrieve(img,'%s.png'%i)
i+=1
html=getHtml("http://gl.sanguosha.com/")
print getImg(html) 木有报错内容,差评!{:10_277:} ~风介~ 发表于 2017-3-7 20:30
木有报错内容,差评!
可是用Pycharm ,运行会报错。就没法下载到本地
页:
[1]