如何将 Twitter 搜索结果限制在一个国家/地区 [英] How to restrict the results of a Twitter search to one country

查看:118
本文介绍了如何将 Twitter 搜索结果限制在一个国家/地区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Twitter API 来复习我的基本 Python.我正在构建一个应用程序,用于扫描来自我的国家(爱尔兰)的推文,以逐个县为单位扫描是否存在亵渎性内容,以查看流行内容并绘制结果图表.

I'm playing with the Twitter API to brush up on my basic python. I'm building an app to scan tweets from my country (Ireland) for profanity on a county by county basis, to see what's popular and to graph the results.

我正在使用 python-twitter 库.为了保留我在 Twitter 上的点击量预算,我只想从爱尔兰获得结果.我目前的方式是:1. 使用 python-twitter 的 GetSearch() 在所有推文中搜索单词FU**".2. 这给出了一个状态列表:从每个人中提取 screen_name,这用于获取用户.获取用户()3. 用户具有有效数据或""用于位置字段(用户指定).4. 检查此字段中的县名.

I'm using the python-twitter library. To preserve my budget of hits to Twitter, I'd like to only get results from Ireland. The way I have it at the moment is: 1. Search all tweets for the word "FU**" using python-twitter's GetSearch(). 2. This gives a list of statuses: Pull the screen_name from each one, this is used to get the user. GetUser() 3. The user has valid data or " " for the Location field(user specified). 4. Check for county names in this field.

我还做了一个测试,它使用嵌入在状态中的坐标,但大多数用户都关闭了这个功能.当它起作用时,它运行良好.

I've also done a test which uses the coordinates embedded in a status, but most users have this switched off. It works well, when it works.

那么,如果不使用这些,我可以将搜索限制在一个国家/地区吗?

So, without using these, can I restrict the search to one country?

推荐答案

最直接的方法是在使用搜索 api 时使用 geocode 参数,它应该将您提供的查询字符串和坐标和"在一起.

The most straight forward way is to use the geocode parameter when using the search api, that should "and" together your query string and coordinates you provide.

>

如果这不能提供足够的结果,您还可以使用 geo/reverse_geocode.您将查询您所在国家/地区的坐标,将返回的地名和数据存储在一个集合中.然后只需进行简单的查询字符串搜索,看看是否有任何推文地点字段在您的集合中.

If that doesn't provide enough results, you could also use geo/reverse_geocode. You would query for coordinates within your country, store the returned place names and data in a set. Then just do a plain query string search and see if any of those tweets places field is in your set.

这篇关于如何将 Twitter 搜索结果限制在一个国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆