Python之抓取动态网页
2015-12-24 15:04
549 查看
python之抓取花瓣网图片
实现方法:
1,创建一个文件夹。
2,模拟请求网络服务。
3,匹配抓取的图片。
4,保存。
实现方法:
1,创建一个文件夹。
2,模拟请求网络服务。
3,匹配抓取的图片。
4,保存。
#_*_coding:utf8_*_ import re import os import urllib,urllib2 import sys reload(sys) #创建保存图片文件夹 if(os.path.exists('保存图片文件的名称')==False: os.mkdir('保存图片文件的名称') #模拟请求 def img(): #打开抓取的网页源代码,可以看到pin_id pin_id=网页中的数字 while pin_id !=None url='打开网页的网址?'+str(pin_id) try: i_header={"User-Agent":"打开审查元素,切换到网络,可以看到此项内容,粘贴复制到这里。",、"Referer":'http://baidu.com/(其他浏览器)'} zq=urllib2.Requests(url,headers=i_header html=urllib2.urlopen(zq).read() zqd=re.compile('"user_id":(.*?),.+?"file":{"farm":"farm1", "bucket":"hbimg",.+?"key":"(.*?)",.+?"type":"image/(.*?)"',re.S) groups=re.findall(zqd,html) print "start to catch"+str(len(groups)) for att in groups: pin_id=att[0] att_url = att[1] + '_fw236' img_type = att[2] img_url='http://img.hb.aicdn.com/'+att_url if(urllib.urlretrieve(img_url,'保存图片的文件夹'+att_url+'.'+img_type)): print 'download success' else: print 'downing fail' except: print 'Error' img()
相关文章推荐
- android wifi 无线调试
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例