使用PRAW 4搜索reddit上的帖子,适用于特定的subreddits,但不适用于'all'

时间:2016-12-16 17:14:08

标签: python search reddit

我在脚本应用中使用PRAW 4来搜索reddit。当我在特定的subreddit中搜索时,我得到了一些结果,但是当我尝试搜索'all'subreddit时,我得到零结果。 代码:

all = reddit.subreddit("all")
for i in all.search("yellow car", limit=5):
    print i.title
cars = reddit.subreddit("cars")
for i in cars.search("yellow car", limit=5):
    print i.title

控制台日志:

DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/r/all/search/
DEBUG:prawcore:Headers: {'Authorization': 'bearer tokenremoved'}
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'sort': 'relevance', 'raw_json': 1, 'syntax': 'cloudsearch', 'q': 'yellow car', 'limit': 5, 't': 'all', 'restrict_sr': True}
DEBUG:prawcore:Response: 200 (107 bytes)
DEBUG:prawcore:Fetching: GET https://oauth.reddit.com/r/cars/search/
DEBUG:prawcore:Headers: {'Authorization': 'bearer tokenremoved'}
DEBUG:prawcore:Data: None
DEBUG:prawcore:Params: {'sort': 'relevance', 'raw_json': 1, 'syntax': 'cloudsearch', 'q': 'yellow car', 'limit': 5, 't': 'all', 'restrict_sr': True}
DEBUG:prawcore:Response: 200 (3552 bytes)
Why do most American cars have yellow in their headlights, while foreign equivalents often don't?
The M5 is a great family car!
You can have 2 cars, your daily driver and something else.  You already have your daily driver and 100k (USD) to spend.  What do you buy?
What's in your dream 5-car garage?
I bought my first car today r/cars!

我为“全部”搜索请求挖出了json响应:

{u'kind': u'Listing', u'data': {u'facets': {}, u'modhash': None, u'children': [], u'after': None, u'before': None}}

没有错误,只是空结果。

任何人都知道为什么搜索'all'不会返回结果或者下一步调试这个东西会是什么? 谢谢!

1 个答案:

答案 0 :(得分:1)

此搜索问题是PRAW 4.0.0中的错误。您应该能够通过安装最新的PRAW4开发版来完全搜索。您可以通过以下方式安装该版本:

pip install --upgrade https://github.com/praw-dev/praw/archive/master.zip