#coding =utf-8#---------------------------------------# program: Androidbenchmark Crawler # ewang# Date: 2016-7-11# language: Python 2.7# Function: Gets the Android PassMark rating information in the page to be saved to the file. #---------------------------------------Import stringimport urllib2import reimport osclass androidbenchmark_spider: #申明相关属性def __init__ (Self,url): #给SougoPicUrl属性赋值self. androidbenchmarkurl=url# to save image URL Information self.androidbenchmark=[] Print U ' crawler, crawl ... ' #初始化加载页面并将其转码存储defAndroidBenchMark (self): #读取页面的原始信息Page =urllib2.urlopen ( Self.androidbenchmarkurl). Read () #获取页面标题title =self.find_title (page) Print U ' page name: ' +title# gets the text information on the page self.save_infor (title) #查找页面标题def Find_title (self,page): #匹配 <title>xxxx</title>mytitle=re.search (R ' <title> (. *?) </title> ', Page,re. S) #初始化标题名为暂无标题title =u ' no title ' #如果标题存在把标题赋值给titleif myTitle: # (. *?) This is called a group, starting from 1 title=mytitle.group (1) else:print u ' Reptile report: Unable to load page title ... ' Return title# save page Info def save_infor (self,title ): #加载页面文本信息到数组中self. Get_infor () #创建并打开本地文件f =open (title+ '. csv ', ' w+ ') #把获取的页面信息写入文件中f. WriteliNES (Self.androidbenchmark) #关闭打开的文件f. Close () Print U ' crawler report: File ' +title+ '. csv ' +u ' has been downloaded: ' +OS.GETCWD () print U ' Press any key to exit ... ' Raw_input () #获取页面源码并将其存储到数组中def get_infor (self): #获取页面中的源码page =urllib2.urlopen (Self.androidbenchmarkurl). Read () # Extract the URL of all JPG images in the page Self.deal_android_device (page) def deal_android_device (self,page): #获取所有设备名称Android_Device = Re.findall (' \<a href=\ ' phone\.php\?phone= (. *?) \ "\>", Page,re. S) #把手机型号的添加到androidbenchmark列表中for AItem in Android_Device:self.androidbenchmark.append (aitem+ "\ n") #------------ Program Entrance----------------print U "" #---------------------------------------# Program: Program: Androidbenchmark Crawler # ewang# Date: 2016-7-7# language: Python 2.7# feature: Gets the Android PassMark rating information from the page to the file. #--------------------------------------------------"" #print u ' need to crawl get URL (passmark_chart,memmark_chart,cpumark_ Chart,diskmark_chart,g2dmark_chart,g3dmark_chart): ' #bdurl = ' http://www.androidbenchmark.net/' + str (raw_input ( U ' http://www.androidbenchmark.net/') + '. html ' and_ipone=[' Http://www.androidbenchmark.net/', ' http://www.iphonebenchmark.net/']chart_page=[' passmark_chart.html ', ' memmark_chart.html ', ' Cpumark_ Chart.html ', ' diskmark_chart.html ', ' g2dmark_chart.html ', ' g3dmark_chart.html ']for dev in and_ipone:for chart in Chart_ Page:bdurl=dev+chartandroid_device_name=androidbenchmark_spider (Bdurl) Android_device_name.androidbenchmark ()
#coding =utf-8#---------------------------------------# program: Androidbenchmark Crawler # ewang# Date: 2016-7-11# language: Python 2.7# Function: Gets the Android PassMark rating information in the page to be saved to the file. #---------------------------------------Import stringimport urllib2import reimport osclass androidbenchmark_spider: #申明相关属性def __init__ (Self,url): #给SougoPicUrl属性赋值self. androidbenchmarkurl=url# to save image URL Information self.androidbenchmark=[] Print U ' crawler, crawl ... ' #初始化加载页面并将其转码存储defAndroidBenchMark (self): #读取页面的原始信息Page =urllib2.urlopen ( Self.androidbenchmarkurl). Read () #获取页面标题title =self.find_title (page) Print U ' page name: ' +title# gets the text information on the page self.save_infor (title) #查找页面标题def Find_title (self,page): #匹配 <title>xxxx</title>mytitle=re.search (R ' <title> (. *?) </title> ', Page,re. S) #初始化标题名为暂无标题title =u ' no title ' #如果标题存在把标题赋值给titleif myTitle: # (. *?) This is called a group, starting from 1 title=mytitle.group (1) else:print u ' Reptile report: Unable to load page title ... ' Return title# save page Info def save_infor (self,title ): #加载页面文本信息到数组中self. Get_infor () #创建并打开本地文件f =open (title+ '. csv ', ' w+ ') #把获取的页面信息写入文件中f. WriteliNES (Self.androidbenchmark) #关闭打开的文件f. Close () Print U ' crawler report: File ' +title+ '. csv ' +u ' has been downloaded: ' +OS.GETCWD () print U ' Press any key to exit ... ' Raw_input () #获取页面源码并将其存储到数组中def get_infor (self): #获取页面中的源码page =urllib2.urlopen (Self.androidbenchmarkurl). Read () # Extract the URL of all JPG images in the page Self.deal_android_device (page) def deal_android_device (self,page): #获取所有设备名称Android_Device = Re.findall (' \<a href=\ ' phone\.php\?phone= (. *?) \ "\>", Page,re. S) #把手机型号的添加到androidbenchmark列表中for AItem in Android_Device:self.androidbenchmark.append (aitem+ "\ n") #------------ Program Entrance----------------print U "" #---------------------------------------# Program: Program: Androidbenchmark Crawler # ewang# Date: 2016-7-7# language: Python 2.7# feature: Gets the Android PassMark rating information from the page to the file. #--------------------------------------------------"" "Print U" requires crawl to get URL (passmark_chart,memmark_chart,cpumark_ Chart,diskmark_chart,g2dmark_chart,g3dmark_chart): ' Bdurl = ' http://www.androidbenchmark.net/' + str (raw_input ( U ' http://www.androidbenchmark.net/') + '. html ' Android_device_name=androidbenchmark_spider (Bdurl) Android_device_name.androidbenchmark ()
#coding =utf-8#---------------------------------------# program: Iphonebenchmark Crawler # ewang# Date: 2016-7-11# language: Python 2.7# Function: Get the iphone PassMark rating information from the page to the file. #---------------------------------------Import stringimport urllib2import reimport osclass iphonebenchmark_spider:# Declaration of related Properties def __init__ (Self,url): #给SougoPicUrl属性赋值self. iphonebenchmarkurl=url# to save image URL Information self.iphonebenchmark=[] Print U ' crawler, crawl ... ' #初始化加载页面并将其转码存储defiphoneBenchMark (self): #读取页面的原始信息Page =urllib2.urlopen (Self.iphonebenchmarkurl ). Read () #获取页面标题title =self.find_title (page) Print U ' page name: ' +title# gets the text information in the page self.save_infor (title) #查找页面标题def Find_ Title (self,page): #匹配 <title>xxxx</title>mytitle=re.search (R ' <title> (. *?) </title> ', Page,re. S) #初始化标题名为暂无标题title =u ' no title ' #如果标题存在把标题赋值给titleif myTitle: # (. *?) This is called a group, starting from 1 title=mytitle.group (1) else:print u ' Reptile report: Unable to load page title ... ' Return title# save page Info def save_infor (self,title ): #加载页面文本信息到数组中self. Get_infor () #创建并打开本地文件f =open (title+ '. csv ', ' w+ ') #把获取的页面信息写入文件中f. Writelines (selF.iphonebenchmark) #关闭打开的文件f. Close () Print U ' crawler report: File ' +title+ '. csv ' +u ' has been downloaded: ' +OS.GETCWD () print U ' Press any key to exit ... ' raw_input () #获取页面源码并将其存储到数组中def get_infor (self): #获取页面中的源码page =urllib2.urlopen (Self.iphonebenchmarkurl). Read () # Extract the URL of all JPG images in the page Self.deal_iphone_device (page) def deal_iphone_device (self,page): #获取所有设备名称iphone_Device = Re.findall (' \<a href=\ ' phone\.php\?phone= (. *?) \ "\>", Page,re. S) #把手机型号的添加到iphonebenchmark列表中for AItem in iphone_Device:self.iphonebenchmark.append (aitem+ "\ n") #------------ Program Entrance----------------print U "" #---------------------------------------# Program: Program: Iphonebenchmark Crawler # ewang# Date: 2016-7-7# language: Python 2.7# feature: Gets the iphone PassMark rating information from the page to the file. #--------------------------------------------------"" "Print U" requires crawl to get URL (passmark_chart,memmark_chart,cpumark_ Chart,diskmark_chart,g2dmark_chart,g3dmark_chart): ' Bdurl = ' http://www.iphonebenchmark.net/' + str (raw_input ( U ' http://www.iphonebenchmark.net/') + '. html ' Iphone_device_name=iphonebenchmark_spider (bdurl) Iphone_Device_name.iphonebenchmark ()
Androidbenchmark and Iphonebenchmark The device information crawler in these two pages