V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-09-06 17:15:47 +08:00 · 3443 次点击
    这是一个创建于 1686 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如:

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

    css seletor 语法,你可以去了解下完整的语法示例,
    Mitt
        3
    Mitt  
       2019-09-07 08:05:31 +08:00 via iPhone
    @Mitt 是 css selector 少敲了个字母
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5223 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:17 · PVG 15:17 · LAX 00:17 · JFK 03:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.