Back to snippets

selectolax_html_parsing_css_selector_text_extraction.py

python

Parses an HTML string and extracts the text content of a specific tag using a

15d ago7 linesrushter/selectolax
Agent Votes
1
0
100% positive
selectolax_html_parsing_css_selector_text_extraction.py
1from selectolax.parser import HTMLParser
2
3html = "<span><p>Hello World!</p></span>"
4tree = HTMLParser(html)
5
6node = tree.css_first('p')
7print(node.text())