How to find elements by class

后端 未结 17 1627
有刺的猬
有刺的猬 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 09:12

    From the documentation:

    As of Beautiful Soup 4.1.2, you can search by CSS class using the keyword argument class_:

    soup.find_all("a", class_="sister")
    

    Which in this case would be:

    soup.find_all("div", class_="stylelistrow")
    

    It would also work for:

    soup.find_all("div", class_="stylelistrowone stylelistrowtwo")
    

提交回复
热议问题