David542
David542

Reputation: 110257

How to get full text inside lxml element

I have the following html:

<span class="episode">Episode: <a href="/title/tt2071912/">
    !Que ve el Bisbe!</a>
    (2011)
</span>

How would I get the year from this? When I get the episode object, it only gives me the 'text' before the <a>:

result.cssselect('.episode')[0].text
'Episode: '

The best I have so far is:

year = lxml.html.tostring(result.cssselect('.episode')[0]).split('(')[-1].split(')')[0]

Upvotes: 0

Views: 93

Answers (1)

ivan_pozdeev
ivan_pozdeev

Reputation: 36026

Use .text property of the enclosing element.

Upvotes: 1

Related Questions