我是靠谱客的博主 唠叨酸奶,这篇文章主要介绍python爬虫入门教程之点点美女图片爬虫代码分享,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- 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爬虫入门教程之点点美女图片爬虫代码分享的全部内容,更多相关python爬虫入门教程之点点美女图片爬虫代码分享内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(143)

评论列表共有 0 条评论

立即
投稿
返回
顶部