Created
November 21, 2018 17:46
-
-
Save naranjja/6026eb7104ca3d0731bd33b8f7ade24e to your computer and use it in GitHub Desktop.
Get body HTML from HTML string using LXML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install lxml cssselect | |
import lxml.html | |
from lxml import etree | |
html = """ | |
<html> | |
<body> | |
<p>Hello world</p> | |
</body> | |
</html> | |
""" | |
tree = lxml.html.fromstring(html) | |
body_html = etree.tostring(tree.cssselect("body")[0]).decode("utf-8") | |
print(body_html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment