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

Python 新手寻求帮助-如何在 Python 中使用 beautifulsoup 获取 onclick 的信息?

  •  
  •   zhcq163 · Jul 27, 2018 · 3578 views
    This topic created in 2868 days ago, the information mentioned may be changed or developed.

    大神们好,我已经将某页面进行格式化处理,将所需要的内容格式化成<a href="javascript:void(0)" onclick="showInfo('XXXXXXXXXXXXXXX'),但是我想获取到 onclick 内的所有 XXXXXXXXXXXX 的字符串信息,这个应该怎么操作,谢谢

    6 replies    2018-07-27 16:11:01 +08:00
    KeatingSmith
        2
    KeatingSmith  
       Jul 27, 2018 via iPhone
    re.findall(r ’<a.*?onclick=“ showInfo\(\’(.*?)\’\).*?>’, text)
    yanzixuan
        3
    yanzixuan  
       Jul 27, 2018
    soup.find('a').attrs.get("onclick", "")
    ddzzhen
        4
    ddzzhen  
       Jul 27, 2018 via Android
    正则即可
    zhcq163
        5
    zhcq163  
    OP
       Jul 27, 2018
    @ddzzhen 正则应该怎么写
    glaucus
        6
    glaucus  
       Jul 27, 2018
    @zhcq163 二楼就是给你写的正则呀,而且这个用 substring 也可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1888 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 16:14 · PVG 00:14 · LAX 09:14 · JFK 12:14
    ♥ Do have faith in what you're doing.