python爬取贴吧图片
来源:互联网 发布:巫师3低配置优化 编辑:程序博客网 时间:2024/06/07 22:58
将http://tieba.baidu.com/p/5072919394 里的图片爬到本地。
版本 phthon 3.x
#coding=utf-8import urllib.requestimport redef getHtml(url): page=urllib.request.urlopen(url) #page 是http.client.HTTPResponse object 无法直接读取里面内容,所以调用read方法,得到页面代码,再将bytes转成string类型 Html=str(page.read()) print("succeed in getting html:\n %s" %Html) return Htmldef getImg(Html): # (?<=pattern) 反向肯定预查,与正向肯定预查类拟,只是方向相反。例如,“(?<=95|98|NT|2000)Windows"能匹配"2000Windows"中的"Windows",但不能匹配"3.1Windows"中的"Windows"。 img_re = re.compile(r'(?<=src=")\S+?jpg') img_list=img_re.findall(Html) for i in range(len(img_list)): print("img_list[%d]=%s" % (i,img_list[i])) #根据图片url地址,用urllib.request.retrieve下载到本地 urllib.request.urlretrieve(img_list[i], '%s.jpg' % i)if __name__=="__main__": url="http://tieba.baidu.com/p/5072919394" html=getHtml(url) getImg(html)
阅读全文
0 0
- [Python爬虫]爬取贴吧图片
- Python爬取贴吧图片
- python爬取贴吧图片
- 用Python 爬虫爬取贴吧图片
- Python爬虫入门——爬取贴吧图片
- Python爬虫__爬取贴吧图片和文本
- 使用Python爬虫爬取贴吧图片数据
- Python第一个爬虫(爬取贴吧图片)
- Python 图片处理-图片翻转
- Python 图片处理-图片翻转
- [图片]Ruby vs Python
- python 图片搜索
- Python 图片拼接
- 一张图片入门Python
- python抓取网页图片
- python-Image处理图片
- Python批量下载图片
- python 抓图片
- 转载文章(做个记录)hardstone1
- Java分支结构
- 关于间址周期和执行周期的取操作数的疑问
- 基于文本,优于轻量,用于交换数据——json解析(下篇)
- Maven系列笔记(二)—— Maven的本地仓库、中央仓库与私服
- python爬取贴吧图片
- 28.ResponseEntity与ResponseBody注解的关系
- spring-data-redis spring-boot日常
- 软件设计原则:低耦合高内聚
- @Aspect
- 为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里面有效? 为什么我使用source /etc/profile这个命令之后,新的环境变量只能在一个终端里
- 安卓的打包发布
- 【剑指offer】合并两个排序的链表
- Android Fragment 你应该知道的一切