Get contents by class names using Beautiful Soup

后端 未结 6 527
有刺的猬
有刺的猬 2020-12-28 19:43

Using Beautiful Soup module, how can I get data of a div tag whose class name is feeditemcontent cxfeeditemcontent? Is it:

soup.cla         


        
6条回答
  •  佛祖请我去吃肉
    2020-12-28 19:59

    soup.findAll("div", class_="feeditemcontent cxfeeditemcontent")

    So, If I want to get all div tags of class header

    from stackoverflow.com, an example with BeautifulSoup would be something like:

    from bs4 import BeautifulSoup as bs
    import requests 
    
    url = "http://stackoverflow.com/"
    html = requests.get(url).text
    soup = bs(html)
    
    tags = soup.findAll("div", class_="header")
    

    It is already in bs4 documentation.

提交回复
热议问题