How to find elements by class

后端 未结 17 1425
有刺的猬
有刺的猬 2020-11-22 08:33

I\'m having trouble parsing HTML elements with \"class\" attribute using Beautifulsoup. The code looks like this

soup = BeautifulSoup(sdata)
mydivs = soup.fi         


        
17条回答
  •  粉色の甜心
    2020-11-22 08:57

    As of BeautifulSoup 4+ ,

    If you have a single class name , you can just pass the class name as parameter like :

    mydivs = soup.find_all('div', 'class_name')
    

    Or if you have more than one class names , just pass the list of class names as parameter like :

    mydivs = soup.find_all('div', ['class1', 'class2'])
    

提交回复
热议问题