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
jyb002
V2EX  ›  Python

Scrapy 中 bloom filter 配置是否有效?以及分布式爬虫 scrapy-redis 的问题

  •  
  •   jyb002 · 2015-09-22 06:17:07 +08:00 · 6110 次点击
    这是一个创建于 3140 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我搜索别人的例子,只找到了: http://alexeyvishnevsky.com/?p=26

    我为了方便修改,我是直接把原本官方文档里的 set ()换成了 BloomFilter ()
    想确认下这么写是正确的吗?

    from pybloom import BloomFilter
    from scrapy.exceptions import DropItem

    class Pipeline(object):

    def __init__(self):
        self.bf = BloomFilter(capacity=10000, error_rate=0.0001)
    
    def process_item(self, item, spider):
        md5=md5(url)
        if md5 in self.bf:
            raise DropItem("Duplicate item found: %s" % md5)
        else:
            self.bf.add(md5)
    

    我想分布式处理爬虫,看了 scrapy-redis: https://github.com/darkrho/scrapy-redis
    看他启动 distributed crawling 是通过 pause/resume 实现的吗?能不能事先设置爬虫的数量来代替?
    并且, 他的 scraping 和 post-processing 是分开的吗?也就是 scrpaing/crawling 得到 item 是分布式的,但后处理 item 比方说 item pipeline 之类的还是单线程的?
    大家有什么好的分布式的 scrapy 爬虫包推荐吗?

    6 条回复    2015-09-22 20:39:24 +08:00
    sunchen
        1
    sunchen  
       2015-09-22 07:01:11 +08:00
    scrapy-redis 只是把任务队列和 request 的去重交给了 redis 来做,你如果要用 bloomfilter ,需要把 bllomfilter 的数据丢到 redis ,这个轮子可以自己用 redis 的 bit 相关操作来实现,不过印象中好像 redis 已经要支持 bloomfilter 了, scrapy 本身不支持任和分布式的操作,他也只有一个进程,下载页面的异步的而非分布式并行的
    est
        2
    est  
       2015-09-22 08:59:48 +08:00
    redis 不支持 bloomfilter ,但是支持 hyperloglog ,可以当 bloomfilter 来使用。
    sunchen
        3
    sunchen  
       2015-09-22 09:04:21 +08:00
    @est 那就用 SETBIT 和 GETBIT 操作模拟一个
    sunchen
        4
    sunchen  
       2015-09-22 09:06:08 +08:00
    @est 刚查了下 Bloom filters 要在 Redis 3.2 才能直接集成
    est
        5
    est  
       2015-09-22 09:47:14 +08:00
    @sunchen getbit setbit 可以实现,但是 pfadd pfcount 不也行么。
    jyb002
        6
    jyb002  
    OP
       2015-09-22 20:39:24 +08:00
    @sunchen
    @est
    大神们,那我如果不用 redis ,像我上面写的是正确使用 bloomfilter 了吗?
    然后我看了下,按 sunchen 说的, scrapy 的确是自身不支持 distributed 。但要实现的话,像这个里面 https://github.com/gnemoug/distribute_crawler/tree/master/woaidu_crawler/woaidu_crawler/scrapy_redis 是自己重新写了 dupefilter 和 scheduler 等。所以你们有相关经验,或者详细的教程吗?
    谢啦
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   879 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 102ms · UTC 21:24 · PVG 05:24 · LAX 14:24 · JFK 17:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.