推荐学习书目
› 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
soulmine
V2EX  ›  Python

只是改了一行代码 爬虫的效率就低了几十倍 求解

  •  
  •   soulmine · Aug 31, 2016 · 4000 views
    This topic created in 3689 days ago, the information mentioned may be changed or developed.

    上略: s = k.decode("unicode_escape") ll = re.findall('(.aaaa.)',s ) 下略: 在标题中寻找特定的英文字段 一个大约跑 12s 一个循环 40 个循环大约 8 分钟分钟左右 上略: s = str(k.decode("unicode_escape")) ll = re.findall('(.汉字 XXX.)', s) 下略: 在标题中寻找特定的中文字段 第一个循环 10s 左右 越往后越慢 到最后一个循环是 200s 10 个循环大约有半个小时 我想知道的是为嘛寻找英文和寻找中文的时间差距这么大 其他代码完全一样 服务器也是同一台机器

    4 replies  •  2016-09-01 08:12:18 +08:00
    huntzhan
        1
    huntzhan  
       Aug 31, 2016
    我猜是你 regex 写得太烂导致的, 你看下是否存在 catastrophic backtracking.
    soulmine
        2
    soulmine  
    OP
       Aug 31, 2016
    @huntzhan 呃 这个怎么看.....
    Tyanboot
        3
    Tyanboot  
       Aug 31, 2016
    也许是因为汉字占两个字节?然后匹配的时间暴增?
    simple2025
        4
    simple2025  
       Sep 1, 2016
    你确定正则能这样用中文吗?我记得应该不行吧。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3191 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 12:54 · PVG 20:54 · LAX 05:54 · JFK 08:54
    ♥ Do have faith in what you're doing.