V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Ewig
V2EX  ›  Python

Python 中的 scrapy 中的 mongodb 去重与下载

  •  
  •   Ewig · 2018-09-29 16:48:08 +08:00 · 1110 次点击
    这是一个创建于 2029 天前的主题,其中的信息可能已经有所发展或是发生改变。

    def process_item(self, item, spider): url = item['file_url'] name = item['name']

        result = self.post.aggregate(
            [
                {"$group": {"_id": {"url": url, "name": name}}}
            ]
        )
        if result:
            pass
        else:
    
            self.post.insert({"url": url, "name": name})
            return item
    
    def file_path(self, request, response=None, info=None):
        return request.meta.get('filename', '')
    

    现在情况是这样,我想去组合键去重,然后没有的话就入数据库,然后下载,但是这个是框架里面的下载,我现在想在插入数据库后 直接下载,这个怎么调动那个 下载函数呢?

    def get_media_requests(self, item, info):
        file_url = item['file_url']
        meta = {'filename': item['name']}
        yield Request(url=file_url, meta=meta)
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5206 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:24 · PVG 17:24 · LAX 02:24 · JFK 05:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.