Code: Alles auswählen
from lxml import etree
html = etree.fromstring("<html><a>Hallo</a> Welt <b>!</b></html>")
print html.find("a").text #=> Hallo
print html.find("b").text #=> !
Alternativ kann ich auch dies machen, hilft mir aber auch nicht wirklich:
Code: Alles auswählen
from lxml import html
doc = html.fromstring("<html><a>Hallo</a> Welt <b>!</b></html>")
print doc.find("body").text_content() #=> Hallo Welt !
Code: Alles auswählen
print doc.find("body").find("a").xpath("following-sibling::text()")[0] #=> Welt