我正在尝试创建一个 Reddit 抓取工具,它从 Reddit 主页获取前 100 页并将它们存储到 MongoDB 中。我不断收到错误:
TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
Run Code Online (Sandbox Code Playgroud)
这是我的代码
import pymongo
import praw
import time
def main():
fpid = os.fork()
if fpid!=0:
# Running as daemon now. PID is fpid
sys.exit(0)
user_agent = ("Python Scraper by djames v0.1")
r = praw.Reddit(user_agent = user_agent) #Reddit API requires user agent
conn=pymongo.MongoClient()
db = conn.reddit
threads …Run Code Online (Sandbox Code Playgroud)