gpt4 book ai didi

xpath - 使用 xPath 解析元标记

转载 作者:行者123 更新时间:2023-12-01 22:40:34 25 4
gpt4 key购买 nike

如何解析元标记,例如

<meta itemprop="email" content="email@example.com" class="">

..并从中提取电子邮件。

当我复制此标签的 xPath 时,我得到以下内容,但不起作用

//*[@id="businessDetailsPrimary"]/div[2]/div/meta

请指教。

非常感谢

最佳答案

itemprop="email" 属性很可能在整个网页中是唯一的。在这种情况下,您可以通过 XPath 访问 content 属性来选择电子邮件,如下所示:

//meta[@itemprop="email"]/@content

<强> Demo

如果 itemprop="email" 不唯一,您可以通过选择 id 等于的元素来使您的 XPath 更加具体首先是businessDetailsPrimary:

//*[@id="businessDetailsPrimary"]//meta[@itemprop="email"]/@content

<强> Demo

关于xpath - 使用 xPath 解析元标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35974853/

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