Python获取饭否热词

写了个脚本用来获取饭否热词用Cron第小时抓取一次看看大家都在关注什么

#! /usr/bin/python
# -*-coding:utf8-*-

from curl import Curl
import simplejson

url = "<a href="http://api.fanfou.com/trends.json">http://api.fanfou.com/trends.json</a>"
fan_Curl = Curl(url)
fan_t = fan_Curl.get()
fan_Curl.close()
fan_d = simplejson.loads(fan_t)
data = []
data.append(fan_d["as_of"])
for i in fan_d["trends"]:
data.append(i["name"])
data.append(i["query"])
d = "\t".join(data) + "\n"
#print d
import codecs
fandou_trends = codecs.open("fanfou_trends","a","utf-8")
fandou_trends.write(d)
fandou_trends.close()
Advertisements
此条目发表在Python分类目录。将固定链接加入收藏夹。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s