Using beautiful soup to get html attribute value

前端 未结 2 1732
暗喜
暗喜 2021-01-24 05:05

What i\'m trying to do is use beautiful soup to get the value of an html attribute.

What i have so far is:

soup = BeautifulSoup(html, \"html.parser\")
         


        
2条回答
  •  迷失自我
    2021-01-24 05:58

    you should try the following

    soup = BeautifulSoup(html, "html.parser")
    print("data-sitekey=" + soup.find("div", attrs={"class" : "data-sitekey"}))
    return soup.find("div", attrs={"class" : "data-sitekey"})
    

提交回复
热议问题