Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

代码在没有override on_result函数时,可以将爬取的数据存入pyspider自带的resultdb中。
但是override以后却无法将结果存入Mongodb中。
congfig.json文件:

{
      "taskdb": "mongodb+taskdb://127.0.0.1:27017/pyspider_taskdb",
      "projectdb": "mongodb+projectdb://127.0.0.1:27017/pyspider_projectdb",
      "resultdb": "mongodb+resultdb://127.0.0.1:27017/pyspider_resultdb",
      "message_queue": "redis://127.0.0.1:6379/db",
      "webui": {
                    "port": 5001
    }
}

重载的on_result函数:

    def on_result(self, result):
        if not result:
            return

        client = pymongo.MongoClient(host='127.0.0.1', port=27017)
        db = client['pyspider_resultdb']
        coll = db['website']

        data = {
              'title': result['title'],
              'tags': result['tags'],
              'description': result['description'],
              'website_url': result['website_url'],
              'image_url_list': result['image_url_list']
        }

        data_id = coll.insert(data)
        print (data_id)

运行后没有报错,一切正常,但是mongo中却只有两个数据库,没有pyspider_resultdb:
图片描述

每次新建的任务都会在pyspider_taskdb里更新,但是不知道结果去哪了。
python版本2.7,mongodb版本3.4, pymongo版本3.4。
搞了好久实在不知道问题出在哪里,恳请各位高人指点,谢谢~!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
625 views
Welcome To Ask or Share your Answers For Others

1 Answer

pyspider 会自动去重,抓过的连接不会重新抓取,你采取了什么措施让它重抓了吗?
例如 http://docs.pyspider.org/en/l...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...