各位用户为了找寻关于python妹子图简单爬虫实例的资料费劲了很多周折。这里教程网为您整理了关于python妹子图简单爬虫实例的相关资料,仅供查阅,以下为您介绍关于python妹子图简单爬虫实例的详细内容
本文实例讲述了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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67#!/usr/bin/env python
#coding: utf-8
import
urllib
import
urllib2
import
os
import
re
import
sys
#显示下载进度
def
schedule(a,b,c):
'''''
a:已经下载的数据块
b:数据块的大小
c:远程文件的大小
'''
per
=
100.0
*
a
*
b
/
c
if
per >
100
:
per
=
100
print
'%.2f%%'
%
per
#获取html源码
def
getHtml(url):
page
=
urllib.urlopen(url)
html
=
page.read()
return
html
#下载图片
def
downloadImg(html, num, foldername):
picpath
=
'%s'
%
(foldername)
#下载到的本地目录
if
not
os.path.exists(picpath):
#路径不存在时创建一个
os.makedirs(picpath)
target
=
picpath
+
'/%s.jpg'
%
num
myItems
=
re.findall(
'<p><a href="http://www.mzitu.com/.*?" ><img src="(.*?)" id="codetool">
希望本文所述对大家的Python程序设计有所帮助。