您的位置:首页 > 编程语言 > Python开发

使用简易Python爬虫下载百度贴吧图片

2014-05-21 16:16 741 查看
百度贴吧有贴吧的帖子中有很漂亮的图片,如桌面贴吧有很多适合做系统桌面壁纸的图片,而是用一次一次的下载很是麻烦,所以是用Python写了一个简易的脚本,写的不好,希望大家不要见笑,新手。


Python代码如下:

#!/usr/bin/python
import re
import urllib

def getHtml(url):
page=urllib.urlopen(url)
html=page.read()
return html

def getImg(html):
reg=r'src="(.*?\.jpg)"'
imgre=re.compile(reg)
imglist=re.findall(imgre,html)
x=0
for imgurl in imglist:
urllib.urlretrieve(imgurl,'%s.jpg'%x)
x+=1

y=raw_input('Please input your URL:>')
html=getHtml(y)

getImg(html)


有问题可以咨询我的SINA微博:@Lyndonneu
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 下载 爬虫