So I have a html like this:
...
<ul class="myclass">
<li>blah</li>
<li>blah2</li>
</ul>
...
I want to get the texts “blah” and “blah2” from the ul with the class name “myclass”
So I tried to use innerhtml(), but for some reason it doesn’t work with lxml.
I’m using Python 3.
I would try:
edit:
what if there was a <a> in the <li>? for example, how would I get "link" and text" from <li><a href="link">text</a></li>?If you want you can combine those, and if we take @larsmans example, you can use
'//'to get the whole text, because I belive that lxml does’t support thestring()method in an expression.Also, you can use the
text_content()method:prints: