There is a piece of html code as follows:
<p class="col-9 d-inline-block text gray mb-2 pr-4">
My <em>Python</em> Examples
</p>
What should I do if I want to use xpath to extract My Python Examples
淡淡烟草味2017-05-18 10:59:45
Read more help documents!
//p[@class="col-9 d-inline-block text gray mb-2 pr-4"]/text()
天蓬老师2017-05-18 10:59:45
Refer to this answer of mine:/q/10...
But I discovered a new method, p_dom.xpath("string()")
,可以直接取出内容作为一个完整的字符串;
然后就是lxml.etree
中的方法:etree.tostring(p_dom, method='text')
, but you still have to choose according to your needs.