A little question about xpath in Python
过去多啦不再A梦
过去多啦不再A梦 2017-05-18 10:57:45
0
2
855

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

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
淡淡烟草味

Read more help documents!

//p[@class="col-9 d-inline-block text gray mb-2 pr-4"]/text()

Peter_Zhu

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!