2015-06-20 70 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

評論老問題: 因爲它可能會幫助其他人在未來尋找這個。