How to find tags with only certain attributes - BeautifulSoup

后端 未结 6 799
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 05:23

How would I, using BeautifulSoup, search for tags containing ONLY the attributes I search for?

For example, I want to find all

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 05:36

    Adding a combination of Chris Redford's and Amr's answer, you can also search for an attribute name with any value with the select command:

    from bs4 import BeautifulSoup as Soup
    html = '.....\
        .......\
        .....'
    soup = Soup(html, 'lxml')
    results = soup.select('td[valign]')
    

提交回复
热议问题