我只是在为xPath而苦苦挣扎。我已经读了几本指南,但我似乎就是搞不懂。
基本上,我想提取所有包含"/ro_ro/"的URLs。
<link rel="alternate" href="https://www.stackoverflow.com/pl_pl/" hreflang="pl-PL">
<link rel="alternate" href="https://www.stackoverflow.com/pt_br/" hreflang="pt-BR">
<link rel="alternate" href="https://www.stackoverflow.com/pt_pt/" hreflang="pt-PT">
<link rel="alternate" href="https://www.stackoverflow.com/ro_ro/" hreflang="ro-RO">
<link rel="alternate" href="https://www.stackoverflow.com/fi_fi/" hreflang="fi-FI">理想情况下,xpath查询将返回:https://www.stackoverflow.com/ro_ro/。
我已经接近了,但是页面上有多个链接指向相同的URL,但从来没有使用hreflang属性。
我要大规模地做这件事,我应该注意到这意味着我想要提取的深层页面URL将如下所示:https://www.stackoverflow.com/ro_ro/xpath-help-for-a-noob/
编辑:你知道为什么这会被否决吗?
发布于 2017-03-06 19:32:11
尝试使用下面的XPath从包含href属性的link元素中获取所需的hreflang:
//link[@hreflang and contains(@href, 'ro_ro')]/@href发布于 2017-09-05 15:50:29
您可以使用以下公式在Google电子表格中获取hreflang
=importxml("https://example.org" ,"//link[@hreflang]/@href")发布于 2017-03-06 19:19:03
您应该能够通过以下语句获得这些urls
descendant::link[contains(@href, 'ro_ro')]将文档的基节点作为当前节点
子轴告诉xpath遍历所有子节点。::link表示只选择名称为link的节点,方括号内的表达式表示“只选择href属性包含‘ro_ro’的节点-
https://stackoverflow.com/questions/42624152
复制相似问题