2015-06-20 73 views
0

Basic代码:reddit的Praw API使用搜索提交

import praw 
r = praw.Reddit(user_agent='Getting the data!!') 
r.login("username","password",disable_warning=True) 
results=r.search('whatever', subreddit=None, sort=None, syntax=None, period=None) 
for x in results: 
    print x 

我希望写一个代码来获取所有相关意见和意见。提交内容应受限于搜索查询和时间段。

我面临的问题是:

一个。我无法理解如何在上面指定期限,文档往往很差

b。我不知道结果是否受限制。上面的代码产生:

923 :: Reddit, type with whatever is on your mind no matter how insignificant... 
5598 :: Google maps should have a "on the way" feature to find the most conve... 
3961 :: LPT: If you're overheating for whatever reason, run your wrists under... 
1556 :: As a lad, whenever my mother wanted me to do something and I was play... 
5085 :: "THE ENTIRE STATE IS OFFLINE GET IN THERE NOW FIX IT DO WHATEVER IT T... 
1259 :: Heyy, I do the webcomic "Subnormality," as well as artwork for Cracke... 
604 :: IAMA Professional YouTuber. Whatever that means... AMA is you'd like 
1156 :: [Spoiler] Whatever happened to G2 vs Strix it's an absolute joke 
1217 :: Yesterday I ate whatever I wanted and learned something 
1291 :: LPT: Set Your Plugins (Flash, etc.) to be activated only with your cl... 
1544 :: Whatever you do, don't step on a duck. 
1301 :: A diner in Vegas called "Roulette Burger" where each booth has a roul... 
649 :: Been trying to establish a very simply basic wardrobe. Not too preppy ... 
1141 :: Mods no longer give a shit, post whatever : New Wow expansion doesn't... 
549 :: Whatever happened to chatrooms? 
212 :: IAmA graphic designer who will spend 5 mins on whatever you want. 
673 :: AMA. Hi there, I'm David Ury, I played Spooge in season 2. Please ask ... 
0 :: "Whatever they're going to blame on Osama Bin Laden... don't you even be... 
3 :: Dinner time! 1/4/15 or 4/1/15 (whatever works) 
536 :: Friendly reminder: If you've been given gold, it's perfectly within yo... 
378 :: KP, Keratosis Pillaris, "Chicken skin" - whatever you call it, please ... 
637 :: [WP]What if we lived in a world where whatever you did to other people... 
1053 :: Instead of a gym, have a place where people can go build wood pallets... 
69 :: Pick whatever you want Giveaway! 
408 :: Just a reminder to newbies. you don't have to buy a whole bitcoin for ... 

我非常怀疑必须有很多比这更多。如果是,我怎样才能得到它们。如果请求受限于时间窗口。有没有一些解决方法可以睡觉,然后获得更多?

c。我不知道它是不是像Twitter一样访问历史数据的限制。虽然这段时期的论点相反。仍然不确定。

d。它返回一个发生器。我怎样才能访问完整的提交文本和相关评论的文本。

对不起,如果它看起来有点间接,但缺乏网上的例子和缺乏适当的文件导致面临这些问题。

回答

2

答:它正在寻找'3个月前'之类的东西。 (您可以从API Documentation中看到一些信息,它必须是one of (hour, day, week, month, year, all)

B:它被限制为一个限制,它将返回大约1000个结果max。可能有解决办法,但我不确定它们是什么,或者如何方便他们

C:答案B的种类,我想

d:你正在寻找的提交的属性,您可以通过属性访问(例如, object.attribute)你可以在this page上看到完整的提交属性列表

所以如果y OU想访问一个链接进入自我的文字,你必须做一些事情,如:

for x in results: 
    print x.selftext 

如果你想要得到的意见,不过,这些都不是对象的一部分。您需要获取提交ID,然后查询提交本身以获取评论。

1

默认限制是25,除非在搜索参数中指定了另一个数字。

所以,如果你想要更多的结果,例如100个结果: 结果= r.search( '什么',版(Subreddit)=无,排序=无,语法=无,周期=无,限值为100

评论老问题: 因为它可能会帮助其他人在未来寻找这个。