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

Beautifulsoup.find_all()如何判断有无指定属性?(不判断特定值)

  •  
  •   qazwsxkevin · Sep 6, 2019 · 3923 views
    This topic created in 2505 days ago, the information mentioned may be changed or developed.

    如:

    pageSoup = BeautifulSoup(PageStr,'lxml')
    divSection = pageSoup.select('#somepage')
    for i in divSection.find('tr') #这里如何判断 tr 段的属性,有无 name 和 class 这两个属性,而不管属性值,如果有 name 和 class 属性才为目标...
    
    3 replies    2019-09-07 08:05:31 +08:00
    viakiba
        1
    viakiba  
       Sep 6, 2019 via Android
    xpath
    Mitt
        2
    Mitt  
       Sep 7, 2019 via iPhone
    tr[name][class]

    css seletor 语法,你可以去了解下完整的语法示例,
    Mitt
        3
    Mitt  
       Sep 7, 2019 via iPhone
    @Mitt 是 css selector 少敲了个字母
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5440 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 08:38 · PVG 16:38 · LAX 01:38 · JFK 04:38
    ♥ Do have faith in what you're doing.