标签:
#coding=utf-8 import sys reload(sys) sys.setdefaultencoding( "utf-8" ) import urllib from selenium import webdriver class Qh(): def pc(seif,name,date='7'): #时间默认7天,参数’30’为三十天,’201603|201605’为自定时月份 url_name=urllib.quote(name) #urllib.quote( )将中文url编码 url='http://index.so.com/#trend?q='+url_name+'&t='+date driver = webdriver.PhantomJS() #webdriver.PhantomJS() 调用PhantomJS浏览器 driver.get(url) sszs=driver.find_element_by_xpath('//*[@id="bd_overview"]/div[2]/table/tbody/tr/td[1]').text sszshb=driver.find_element_by_xpath('//*[@id="bd_overview"]/div[2]/table/tbody/tr/td[2]').text sszstb=driver.find_element_by_xpath('//*[@id="bd_overview"]/div[2]/table/tbody/tr/td[3]').text #搜索指数,搜索指数环比,搜索指数同比(均为全国数据) driver.quit #quit( )关闭 return sszs+'|'+sszshb+'|'+sszstb s=Qh() print s.pc('欢乐颂') print s.pc('欢乐颂','30') print s.pc('欢乐颂','201603|201605')
{"status":0,"data":[{"query":"\u6b22\u4e50\u9882","data":{"week_year_ratio":">1000%","month_year_ratio":">1000%","week_chain_ratio":"31.52%","month_chain_ratio":">1000%","week_index":97521,"month_index":47646}}],"msg":false}
#coding=utf-8 import sys reload(sys) sys.setdefaultencoding( "utf-8" ) import urllib from selenium import webdriver class Qh(): def pc(seif,name,dq='全国'): url_name=urllib.quote(name) dq_name=urllib.quote(dq) url='http://index.so.com/index.php?a=overviewJson&q='+url_name+'&area='+dq_name driver = webdriver.PhantomJS() driver.get(url) json=driver.find_element_by_xpath('/html/body/pre').text driver.quit return json s=Qh() print s.pc('欢乐颂') print s.pc('欢乐颂','浙江')
{"status":0,"data":[{"query":"\u6b22\u4e50\u9882","data":{"week_year_ratio":">1000%","month_year_ratio":">1000%","week_chain_ratio":"36.28%","month_chain_ratio":">1000%","week_index":1392286,"month_index":657310}}],"msg":false} {"status":0,"data":[{"query":"\u6b22\u4e50\u9882","data":{"week_year_ratio":">1000%","month_year_ratio":">1000%”,"week_chain_ratio":"31.52%","month_chain_ratio":">1000%","week_index":97521,"month_index":47646}}],"msg":false}
标签:
原文地址:http://blog.csdn.net/u013055678/article/details/51347837