python - 如何利用xpath获取节点中html文本?
大家讲道理
大家讲道理 2017-04-17 16:09:43
[Python讨论组]
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
高洛峰

没猜错的话
用的Scrapy?

sel.xpath() 得到的依旧是一个SelectorList

参看原文档

xpath(query)
Find nodes matching the xpath query and return the result as a SelectorList instance with all elements flattened. List elements implement Selector interface too.

query is a string containing the XPATH query to apply.

那么实际上就是去看Selector 相关的函数了。

————————————————

<p>
    AA
    <sub>1</sub>
    <sub>2</sub>
    <sub>3</sub>
</p>

<p>
    BB
    <sub>1</sub>
    <sub>2</sub>
    <sub>3</sub>
</p>

对于上述例子,其实可以考虑获取到p之后,对其内容再进行一次查找,即可获得 1 、2 、3的内容。

另外
提问的话把自己的环境、代码描述全一点会对自己更有帮助

巴扎黑

试试
abstract =sel.xpath('//p[@id ="abstractBox"]/node()').extract()

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号