如何从Twitter中提取文本fi中标注经纬度的tweet

2024-05-29 03:10:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python从Twitter文本文件中提取经纬度的tweet

例如,我希望在提取的文本文件中包含以下内容:

[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

Tags: thetofromononesstatement文本文件garden
1条回答
网友
1楼 · 发布于 2024-05-29 03:10:57

下面是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将位置转换为“placecode”,然后您需要将其反转:https://dev.twitter.com/terms/geo-developer-guidelines

剩下的(就像他们说的)留给读者做练习:-)

相关问题 更多 >

    热门问题