我想使用python
从文本文件中的Twitter中提取纬度和经度的推文例如,我想在提取的文本文件中包含以下内容:
[50.4146912, -119.2066755] 6 2011-08-28 19:24:29 @NaomiAKlein @TheRealRoseanne "BreakingNews: President Obama to deliver live statement on Hurricane Irene from Rose Garden - NBC News" [38.896544300000002, -76.994223250000005] 6 2011-08-28 19:26:31 RT @ProducerMatthew: President Obama to deliver statement at 2pm PT / 5pm ET on Hurricane #Irene from the Rose Garden. [33.787082099999999, -118.1678924] 6 2011-08-28 19:38:06 Ps. As the joke in itself is what ones know for ones selves as ones do to you yourselves to Obama self, ones government to the police [43.108731089999999, -89.335464060000007] 6 2011-08-28 19:46:44 “@crewislife: US Federal debt increases by U.S Presidents: Reagan 186% Bush I 54% Clinton 41% Bush II 72% Obama 23% Source: CBO #wiunion [43.108731089999999, -89.335464060000007] 6 2011-08-28 19:47:40 RT @crewislife: US Federal debt increases by U.S Presidents: Reagan 186% Bush I 54% Clinton 41% Bush II 72% Obama 23% Source: CBO #wiunion
答案 0 :(得分:2)
以下是指向Twitter REST API的文档的链接。
以下是开始从Twitter下载信息的基础知识:
import urllib2, json, pprint
u = urllib2.urlopen('http://search.twitter.com/search.json?q=obama&rpp=25')
resultdict = json.load(u)
pprint.pprint(resultdict)
for tweet in resultdict['results']:
print tweet['text']
注意,未明确包含long / lat。 Twitter将这些位置转换为“地方代码”,然后您需要将其反转:https://dev.twitter.com/terms/geo-developer-guidelines
其余的(如他们所说)留给读者的练习: - )