Полезный трюк: быстро парсим HTML прямо из строки с помощью selectolax — лёгкой и очень быстрой библиотеки на C, в разы быстрее BeautifulSoup.
Установка:
pip install selectolax
Пример с кодом:
from selectolax.parser import HTMLParser
html = """
<html><body> <h1>Hello</h1> <p class='msg'>World</p> </body></html> """
tree = HTMLParser(html)
print(tree.css_first("h1").text()) # Hello
print(tree.css_first("p.msg").text()) # World
https://www.youtube.com/shorts/CSYJDmt4ztg