如何设置和使用 Praw 进行 Reddit 抓取?
How do I set up and use Praw for Reddit scraping?
我一直在尝试将 Praw 与 Python 2.7 一起使用,但一直遇到问题。这是我遇到的错误:
Traceback (most recent call last):
File "redditscraper.py", line 18, in <module>
subreddit = r.get_subreddit(args.subreddit)
AttributeError: 'Reddit' object has no attribute 'get_subreddit'
这是我的代码:
import praw
import argparse
user_agent = 'PyRedditScraper v0.1 by /u/PizzaFrog'
client_id = 'HIDDEN'
client_secret = 'HIDDEN'
redirect_uri = 'HIDDEN'
parser = argparse.ArgumentParser(description = 'Scrape the specified subreddit')
parser.add_argument('subreddit', help='the subreddit')
args = parser.parse_args()
print 'Scraping /r/' + args.subreddit + '...'
r = praw.Reddit(user_agent = user_agent,
client_id = client_id,
client_secret = client_secret,
redirect_uri = redirect_uri)
subreddit = r.get_subreddit(args.subreddit)
for post in subreddit.get_hot(limit = 10):
print 'title: ' + post.title
print 'text: ' + post.selftext
print 'score: ' + post.score
print '--------------------'
我无法在网上找到任何解决方案,任何帮助将不胜感激。
我还是不知道这个问题出自什么。我从 4.0.2 降级到 3.5,现在工作正常。
我一直在尝试将 Praw 与 Python 2.7 一起使用,但一直遇到问题。这是我遇到的错误:
Traceback (most recent call last):
File "redditscraper.py", line 18, in <module>
subreddit = r.get_subreddit(args.subreddit)
AttributeError: 'Reddit' object has no attribute 'get_subreddit'
这是我的代码:
import praw
import argparse
user_agent = 'PyRedditScraper v0.1 by /u/PizzaFrog'
client_id = 'HIDDEN'
client_secret = 'HIDDEN'
redirect_uri = 'HIDDEN'
parser = argparse.ArgumentParser(description = 'Scrape the specified subreddit')
parser.add_argument('subreddit', help='the subreddit')
args = parser.parse_args()
print 'Scraping /r/' + args.subreddit + '...'
r = praw.Reddit(user_agent = user_agent,
client_id = client_id,
client_secret = client_secret,
redirect_uri = redirect_uri)
subreddit = r.get_subreddit(args.subreddit)
for post in subreddit.get_hot(limit = 10):
print 'title: ' + post.title
print 'text: ' + post.selftext
print 'score: ' + post.score
print '--------------------'
我无法在网上找到任何解决方案,任何帮助将不胜感激。
我还是不知道这个问题出自什么。我从 4.0.2 降级到 3.5,现在工作正常。