python制作花瓣网美女图片爬虫


Posted in Python onOctober 28, 2015

花瓣图片的加载使用了延迟加载的技术,源代码只能下载20多张图片,修改后基本能下载所有的了,只是速度有点慢,后面再优化下

import urllib, urllib2, re, sys, os,requests
path=r"C:\wqa\beautify"
url = 'http://huaban.com/favorite/beauty'
#http://huaban.com/explore/zhongwenlogo/?ig1un9tq&max=327773629&limit=20&wfl=1
i_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36"}
count=0

def urlHandle(url):
  req = urllib2.Request(url, headers=i_headers)
  html = urllib2.urlopen(req).read()
  reg = re.compile(r'"pin_id":(\d+),.+?"file":{"farm":"farm1", "bucket":"hbimg",.+?"key":"(.*?)",.+?"type":"image/(.*?)"', re.S)
  groups = re.findall(reg, html)
  return groups

def imgHandle(groups):
  if 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

      r = requests.get(img_url)
      with open(path + att_url + '.' + img_type, 'wb') as fd:
        for chunk in r.iter_content():
          fd.write(chunk)

groups = urlHandle(url)
imgHandle(groups)

while(groups):
  count+=1
  print count
  pin_id = groups[-1][0]
  print pin_id
  urltemp = url+'/?max=' + str(pin_id) + '&limit=' + str(20) + '&wfl=1'
  print(urltemp)
  groups = urlHandle(urltemp)
  #print groups
  imgHandle(groups)
Python 相关文章推荐
Perl中著名的Schwartzian转换问题解决实现
Jun 02 Python
深入解析Python设计模式编程中建造者模式的使用
Mar 02 Python
Python排序算法实例代码
Aug 10 Python
利用Python-iGraph如何绘制贴吧/微博的好友关系图详解
Nov 02 Python
详解tensorflow实现迁移学习实例
Feb 10 Python
Python基于百度AI的文字识别的示例
Apr 21 Python
Django框架的中的setting.py文件说明详解
Oct 15 Python
WIn10+Anaconda环境下安装PyTorch(避坑指南)
Jan 30 Python
python读取有密码的zip压缩文件实例
Feb 08 Python
python多线程并发实例及其优化
Jun 27 Python
python文件转为exe文件的方法及用法详解
Jul 08 Python
Python自动化实战之接口请求的实现
May 30 Python
python制作最美应用的爬虫
Oct 28 #Python
python使用wmi模块获取windows下的系统信息 监控系统
Oct 27 #Python
详解JavaScript编程中的window与window.screen对象
Oct 26 #Python
深入讲解Python中的迭代器和生成器
Oct 26 #Python
Windows下使Python2.x版本的解释器与3.x共存的方法
Oct 25 #Python
解析Python编程中的包结构
Oct 25 #Python
Python实现获取域名所用服务器的真实IP
Oct 25 #Python
You might like
php文章内容分页并生成相应的htm静态页面代码
2010/06/07 PHP
PHP实现将MySQL重复ID二维数组重组为三维数组的方法
2016/08/01 PHP
thinkPHP框架自动填充原理与用法分析
2018/04/03 PHP
JavaScript 类的定义和引用 JavaScript高级培训 自定义对象
2010/04/27 Javascript
纯JS实现五子棋游戏兼容各浏览器(附源码)
2013/04/24 Javascript
Javascript 浮点运算的问题分析与解决方法
2013/08/27 Javascript
jQuery实现在最后一个元素之前插入新元素的方法
2015/07/18 Javascript
学习Bootstrap滚动监听 附调用方法
2016/07/02 Javascript
js 获取元素所有兄弟节点的实现方法
2016/09/06 Javascript
解决React Native端口号修改的方法
2017/07/28 Javascript
React+Redux实现简单的待办事项列表ToDoList
2019/09/29 Javascript
[02:16]2018年度CS GO最具人气选手-完美盛典
2018/12/16 DOTA
Python基础教程之内置函数locals()和globals()用法分析
2018/03/16 Python
python使用xlrd和xlwt读写Excel文件的实例代码
2018/09/05 Python
python requests 库请求带有文件参数的接口实例
2019/01/03 Python
python实现切割url得到域名、协议、主机名等各个字段的例子
2019/07/25 Python
python实现简易淘宝购物
2019/11/22 Python
Python SSL证书验证问题解决方案
2020/01/13 Python
Python @property及getter setter原理详解
2020/03/31 Python
sklearn和keras的数据切分与交叉验证的实例详解
2020/06/19 Python
Pytorch实现将模型的所有参数的梯度清0
2020/06/24 Python
一文带你了解Python 四种常见基础爬虫方法介绍
2020/12/04 Python
Html5游戏开发之乒乓Ping Pong游戏示例(一)
2013/01/21 HTML / CSS
奥地利网上现代灯具和灯饰店:Lampenwelt.at
2018/01/29 全球购物
在加拿大在线租赁和购买电子游戏:Game Access
2019/09/02 全球购物
在阿尔卑斯山或希腊度过快乐假期:Alpine Elements
2019/12/28 全球购物
Simons官方网站:加拿大时尚零售商
2020/02/20 全球购物
工程项目经理岗位职责
2013/12/15 职场文书
出纳工作岗位责任制
2014/02/02 职场文书
反四风个人对照检查材料思想汇报
2014/09/25 职场文书
2014年度安全工作总结
2014/12/04 职场文书
退休职工欢送会致辞
2015/08/01 职场文书
导游词之西安骊山
2019/12/03 职场文书
ubuntu下常用apt命令介绍
2022/06/05 Servers
MySQL数据管理操作示例讲解
2022/12/24 MySQL
SQL Server数据库的三种创建方法汇总
2023/05/08 MySQL