爬虫关于安智市场的过程

最近,实验室的老师要求写一个爬虫 爬取安智市场的一些应用  我把经历记录在这里 包括 每一次的过程 

便于自己记忆 也帮助其他有需要的人 相信以后能写出更好的代码(如果之后有时间code review

【urllib库编写】

简单 甚至可以说 弱智 但是对入门者 很好理解

可以爬取静态网页 根据domin的变换(手动)爬取更多网页

 1 # -*- coding: utf-8 -*-
 2 """
 3 Created on Wed Jul 11 15:43:00 2018
 4 
 5 @author: LeonardoWang
 6 """
 7 
 8 import re
 9 import urllib
10 import urllib.request
11 
12 url = "http://m.anzhi.com/top_1.html    "
13 page = urllib.request.urlopen(url)
14 html = page.read()
15 html = html.decode('utf-8')
16 
17 #print(html)
18 reg_down = r'href="(.*?)">极速下载</a>'
19 reg_name = r'<h4>(.*?)</h4>'            
20 
21 item_link=[]
22 link = re.compile(reg_down)
23 linklist = re.findall(link, html)
24 
25 item_name=[]
26 name = re.compile(reg_name)
27 namelist = re.findall(name, html)
28 #print(namelist)
29 #print(namelist)
30 
31 #urllib.request.urlretrieve('http://m.anzhi.com/download.php?softid=3001793','今日头条.apk')
32 
33 for n in linklist:
34     item_link.append("http://m.anzhi.com/"+n)
35 #    print(item_link)
36 x=0
37 for a in item_link:
38     print(a)
39     urllib.request.urlretrieve(a,'D:\\apk\\%s.apk' % namelist[x])
40     print("done")
41     x+=1
42 print("Finished")
43 # =============================================================================
44 # for i in range(5):
45 #     print(namelist[i])
46 # =============================================================================
47 #    print (item_name)

【用Selenium写 】

猜你喜欢

转载自www.cnblogs.com/leonardo-Xx/p/9336322.html