代码拉取完成,页面将自动刷新
__author__ = 'evan'
import datetime
import httplib2
import json
STOCK_TYPE = {'hotest' : 274, 'small' : 277, 'startup' : 276}
def baidu_index(stock_type):
date = datetime.date.today()
print date
url = "http://top.baidu.com/clip?line=20&b=" + str(STOCK_TYPE[stock_type])
http_client = httplib2.Http('.cache')
resp, content = http_client.request(url, "GET")
rise_list = []
for i in content.split('\n'):
if 'BD_DATA' in i:
data = i.split('BD_DATA=')[1][:-2]
res_list = json.loads(data)
print '\n== %s most rise in first 5=='%stock_type
for i in res_list[:5]:
if i.get('trend') == 'rise':
print i['title'], i['clicks']
print '\n==most 5=='
for i in res_list[:5]:
print i['title'], i['clicks']
print '\n==most rise =='
for i in res_list:
if i.get('trend') == 'rise':
del i['tit_url']
del i['detail_url']
rise_list.append(i)
print i['title'], i['clicks']
print '\n============================\n'
break
# date = datetime.date.today()
# with open(str(date) + "_baidu_hot_search.txt","w") as fb:
# fb.writelines(json.dumps(rise_list, encoding='gbk'))
if __name__ == '__main__':
stock_types=['hotest', 'small', 'startup']
for i in stock_types:
baidu_index(i)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。