推荐学习书目
› 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 · 4019 views
    This topic created in 2583 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   ·   Privacy   ·   Solana   ·   2260 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    ♥ Do have faith in what you're doing.