|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib
import re
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImg(html):
reg = r'src="(.+?\.jpg)" pic_ext'
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
x = 0
for imgurl in imglist:
urllib.urlretrieve(imgurl,'%s.jpg' % x)
x+=1
html = getHtml("http://tieba.baidu.com/p/2460150866")
print getImg(html)
能不能好好说话?错误确实有,是一样的错误吗?
也免得你找错误了。给你上代码。答案还得靠自己解决
- import urllib.request
- import re
- def getHtml(url):
- page = urllib.request.urlopen(url)
- html = page.read().decode("utf-8")
- return html
- def getImg(html):
- reg = r'src="(.+?\.jpg)" pic_ext'
- imgre = re.compile(reg)
- imglist = imgre.findall(html)
- x = 0
- for imgurl in imglist:
- urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
- x+=1
-
- html = getHtml("http://tieba.baidu.com/p/2460150866")
- print(getImg(html))
复制代码
搞我一桌面图片
|
|