360inx指数

2016-10-28  本文已影响0人  田边女斯基
#http://index.so.com/index.php?a=overviewJson&q=1&area=%E5%85%A8%E5%9B%BD
#baidu的URL加密,不好搞
import requests
import json
import time
path=r'C:/Users/Administrator/Desktop/result/360inx/keywords.txt'
time1 = time.strftime("%H:%M:%S").replace(':','')
finalpath=r'C:/Users/Administrator/Desktop/result/360inx/indexresult'+time1+'.txt'
keywords_list=[]
def final():
    with open(path,'r',encoding='utf-8')as text:
        keywords=text.readlines()
        for keyword in keywords:
            keyword=keyword.strip().replace('\ufeff','')
            keywords_list.append(keyword)
    for keyword in keywords_list:
        try:
            index360(keyword)
        except Exception as e:
            print(e)
            keywords_list.append(keyword)
            time.sleep(10.1)
def index360(keyword):
    url='http://index.so.com/index.php?a=overviewJson&q={}&area=%E5%85%A8%E5%9B%BD'.format(keyword)
    web_date=requests.get(url,timeout=3.0001)
    time.sleep(1.5)#(0.5s是不可取的,175个就炸了)
    jcont=json.loads(web_date.text)
    print(jcont)
    with open(finalpath,'a+',encoding='utf-8') as text:
        if jcont['data']==False:
            print(keyword + 'none')
            text.write(keyword + '@0'*6)
        else:
            print(keyword+str(jcont['data'][0]))
            text.write(
            keyword
            + '@' + str(jcont['data'][0]['data']['month_index'])
            + '@' + str(jcont['data'][0]['data']['month_chain_ratio'])
            + '@' + str(jcont['data'][0]['data']['month_year_ratio'])
            + '@' + str(jcont['data'][0]['data']['week_index'])
            + '@' + str(jcont['data'][0]['data']['week_chain_ratio'])
            + '@' + str(jcont['data'][0]['data']['month_year_ratio'])
            + '\n'
        )







    #'msg': 'no data'
final()
#index360('剑dd圣')
上一篇 下一篇

猜你喜欢

热点阅读