简体   繁体   中英

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]

使用封闭元素的.text属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM