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
Read more help documents!
//p[@class="col-9 d-inline-block text gray mb-2 pr-4"]/text()
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.
p_dom.xpath("string()")
lxml.etree
etree.tostring(p_dom, method='text')
Read more help documents!
//p[@class="col-9 d-inline-block text gray mb-2 pr-4"]/text()
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.