python爬虫入门教程之点点美女图片爬虫代码分享

yipeiwu_com5年前Python爬虫

继续鼓捣爬虫,今天贴出一个代码,爬取点点网「美女」标签下的图片,原图。

# -*- coding: utf-8 -*- 

#--------------------------------------- 
#  程序:点点美女图片爬虫 
#  版本:0.2 
#  作者:zippera 
#  日期:2013-07-26 
#  语言:Python 2.7 
#  说明:能设置下载的页数 
#--------------------------------------- 
 
import urllib2
import urllib
import re
 
 
 
pat = re.compile('<div class="feed-big-img">\n.*?imgsrc="(ht.*?)\".*?')
nexturl1 = "http://www.diandian.com/tag/%E7%BE%8E%E5%A5%B3?page="
 
 
count = 1
 
while count < 2:
 
  print "Page " + str(count) + "\n"
  myurl = nexturl1 + str(count)
  myres = urllib2.urlopen(myurl)
  mypage = myres.read()
  ucpage = mypage.decode("utf-8") #转码
 
  mat = pat.findall(ucpage)
  
 
  
  
  
  if len(mat):
    cnt = 1
    for item in mat:
      print "Page" + str(count) + " No." + str(cnt) + " url: " + item + "\n"
      cnt += 1
      fnp = re.compile('(\w{10}\.\w+)$')
      fnr = fnp.findall(item)
      if fnr:
        fname = fnr[0]
        urllib.urlretrieve(item, fname)
    
  else:
    print "no data"
    
  count += 1

使用方法:新建一个文件夹,把代码保存为name.py文件,运行python name.py就可以把图片下载到文件夹。

相关文章

python抓取某汽车网数据解析html存入excel示例

python抓取某汽车网数据解析html存入excel示例

1、某汽车网站地址2、使用firefox查看后发现,此网站的信息未使用json数据,而是简单那的html页面而已 3、使用pyquery库中的PyQuery进行html的解析 页面样式:...

Python实现爬取百度贴吧帖子所有楼层图片的爬虫示例

Python实现爬取百度贴吧帖子所有楼层图片的爬虫示例

本文实例讲述了Python实现爬取百度贴吧帖子所有楼层图片的爬虫。分享给大家供大家参考,具体如下: 下载百度贴吧帖子图片,好好看 python2.7版本: #coding=utf-...

python爬虫爬取快手视频多线程下载功能

python爬虫爬取快手视频多线程下载功能

环境: python 2.7 + win10 工具:fiddler postman 安卓模拟器 首先,打开fiddler,fiddler作为http/https 抓包神器,这里就不多介绍...

Python使用scrapy抓取网站sitemap信息的方法

本文实例讲述了Python使用scrapy抓取网站sitemap信息的方法。分享给大家供大家参考。具体如下: import re from scrapy.spider import...

一则python3的简单爬虫代码

不得不说python的上手非常简单。在网上找了一下,大都是python2的帖子,于是随手写了个python3的。代码非常简单就不解释了,直接贴代码。 复制代码 代码如下:#test rd...