当前位置: 移动技术网 > IT编程>脚本编程>Python > python爬虫入门教程之点点美女图片爬虫代码分享

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

2019年03月27日  | 移动技术网IT编程  | 我要评论

房顶隔热,2014世界杯在哪举行,战狼2在线观看完整版免费

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

# -*- 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就可以把图片下载到文件夹。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网