Created
February 27, 2019 03:28
-
-
Save xsthunder/ffd4858008eb129c9e23cdd9c7dade0d to your computer and use it in GitHub Desktop.
parse html or xml into dom
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
# see ()[https://stackoverflow.com/a/40749716] | |
from xml.dom.minidom import parseString | |
html_string = """ | |
<!DOCTYPE html> | |
<html><head><title>title</title></head><body><p>test</p></body></html> | |
""" | |
# extract the text value of the document's <p> tag: | |
doc = parseString(html_string) | |
paragraph = doc.getElementsByTagName("p")[0] | |
content = paragraph.firstChild.data | |
print(content) | |
# This would raise an exception on common HTML entities such as or ®. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment