本文實例講述了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程序設計有所幫助。 延伸 · 閱讀
精彩推薦
|