百度贴吧图片抓取工具(Python)
2024-08-23 00:01:48
废话不多说,直接上源码。
import os,urllib,urllib2,re
path='E:/img' #图片保存路径
url=raw_input('Please input URL:')#贴吧地址
pn=1 #贴吧页码
while 1:
address=url+'?'+'pn='+str(pn)#当前页地址
try:
html=urllib2.urlopen(address).read()#读取当前页html
print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!page%d!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'%(pn)
except:
print 'TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT'
exit(0)
m=re.findall('http://imgsrc.baidu.com/forum/w%3D580/sign=.*?\.jpg',html)#利用正则表达式分析图片URL
for i in range(0,len(m)):
print m[i]
n=re.search('sign=(.*?)/',m[i])#提取图片URL部分字符串作为文件名
file_name=n.group(1)+'.jpg'
file_name=os.path.join(path,file_name)
try:
print 'loading...'
urllib.urlretrieve(m[i],file_name)#下载图片
print 'this picture down complete.'
except:
print 'error'
pn=pn+1#翻页
最新文章
- JavaScript中事件处理
- B-index、bitmap-index、text-index使用场景详解
- jQuery知识点总结(第二天)
- C语言中常用的string.h的字符函数
- EAS使用中FineUI的配置
- cocos2dx 2.x mac proj 开启模板
- iptables的recent模块
- [设计模式] 8 组合模式 Composite
- CMake 入门实战 | HaHack
- SKAction类
- Square spiral
- Project configuration is not up-to-date with pom.xml错误解决方法
- bootstrap validator html attributes 选项
- .net core使用RPC方式进行高效的HTTP服务访问
- redis conf 中文详解
- visual studio code常用插件
- 大话设计模式之模板模式 C#
- 经典贪心算法(哈夫曼算法,Dijstra单源最短路径算法,最小费用最大流)
- MySQL防范SQL注入风险
- bzoj 1934 最小割
热门文章
- [读书笔记]了不起的node.js(二)
- UVA 10806 Dijkstra, Dijkstra.(费用流)
- ELK beats通用配置说明(12th)
- Vim Skills——Windows利用Vundle和Github进行Vim配置和插件的同步
- UITabBarController详解
- android131 360 02 设置中心
- NET中間語言(IL) 图解
- 解决Windows2008Server上PLSQL登录时报ORA-12557
- 原 Debian设置开机自动启动与关闭
- mysql之sql语句细节问题汇总