V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
hard2reg
V2EX  ›  Python

断点续爬中的去重问题

  •  
  •   hard2reg · Feb 2, 2024 via iPhone · 2609 views
    This topic created in 816 days ago, the information mentioned may be changed or developed.

    没有用爬虫框架纯手撸 python 代码。

    如果我在读取上次异常终止的参数后,插入数据库时检查记录是否存在( if exists ),是否会很影响整体速度?虽然每条数据都会有一个唯一 id 。需要爬的最终数据条数应该在几百万级(单指存 id 的表)。

    9 replies    2024-02-21 16:09:45 +08:00
    hard2reg
        1
    hard2reg  
    OP
       Feb 2, 2024 via iPhone
    id 设置主键索引了。如果是我杞人忧天了请告诉我。
    lisxour
        2
    lisxour  
       Feb 2, 2024   ❤️ 1
    把 id 放 redis 去重会比较好
    lisxour
        3
    lisxour  
       Feb 2, 2024
    @lisxour 说错,url
    renmu
        4
    renmu  
       Feb 2, 2024 via Android
    直接插,然后重复会报错(狗头)
    vacuitym
        5
    vacuitym  
       Feb 2, 2024   ❤️ 1
    每次 id 插入之前可以试试布隆过滤+redis:id 先布隆过滤,查到的话再去 redis ,真有数据就跳过
    feiniu
        6
    feiniu  
       Feb 2, 2024   ❤️ 1
    断点续爬。整个任务队列,爬取任务完全完成,数据保存成功后,再删除这个任务。

    这样也能杜绝大部分重复
    Maerd
        7
    Maerd  
       Feb 5, 2024   ❤️ 1
    百万级基本不用考虑这个问题,公司的某项目日入数据量达到千万级,使用索引去重才出现性能问题,注意是日入
    ConnorZhang776
        8
    ConnorZhang776  
       Feb 18, 2024
    我赞同使用 bloomFilter + redis 的方法,非常实用,只需要一个简单的 hash 就可以确定是否存在,且可以自定义重复率,个人觉得非常实用
    TTTSHU
        9
    TTTSHU  
       Feb 21, 2024
    可以将 bloomFilter + redis 和 唯一索引 结合起来使用,既不会太影响性能又能保证去重效果
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5615 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 08:23 · PVG 16:23 · LAX 01:23 · JFK 04:23
    ♥ Do have faith in what you're doing.