gpt4 book ai didi

html - xpath如何提取这些内容?

转载 作者:行者123 更新时间:2023-12-03 17:32:55 28 4
gpt4 key购买 nike

有一段这样的HTML代码。
如何获得标题内容?

<a class="question_link" href="/n/1639322" target="_blank">
<div class="question_text_icons">
<span></span>
</div>
"
This is the page title, which I want to get.
"
</a>

我的xpath是
//a[@class="question_link"]/text()

但是输出是
"\n"
"\nThis is the page title, which I want to get.\n"

我只想“这是我想要的页面标题”。

最佳答案

一种选择是找到内部div并获得以下文本同级:

//a[@class="question_link"]/div[@class="question_text_icons"]/following-sibling::text()


或者,获取 last文本节点:

//a[@class="question_link"]/text()[last()]

关于html - xpath如何提取这些内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32173440/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com