Search code examples
pythonhtml-parsing

How do you get specify html text from bs4 parsed response?


I am using this code to parse some context form a url:

response = requests.get(url)
cnbeta_article_content = BeautifulSoup(response.content, "html.parser").find("div", {"class": "cnbeta-article-body"})
return cnbeta_article_content.contents

But I need to get the cnbeta_article_content.contents was a result of list. How do you get the plain html from class cnbeta-article-body of the url? The cnbeta_article_content.text is not the original html.


Solution

  • Does cnbeta_article_content.prettify() render what you expect?