2017-03-06 29 views
0

我只是真的在努力與xPath。我已經閱讀了一些指南,我似乎無法得到正確的答案。使用xpath來提取hreflang的URL

基本上,我想提取所有包含"/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屬性。

我這樣做大規模地,我要指出,這意味着我想提取的樣子深深的網頁網址:https://www.stackoverflow.com/ro_ro/xpath-help-for-a-noob/

編輯:任何想法,爲什麼這讓downvotes?

回答

0

嘗試以下XPath以獲得所需href從包含link元件hreflang屬性:?

//link[@hreflang and contains(@href, 'ro_ro')]/@href 
+0

感謝您迴應獲得在谷歌電子表格中的hreflang,這似乎不適合我,雖然工作的任何想法 –

+0

你的意思是'似乎不適合我'嗎?你得到不正確的輸出或者你得到錯誤?這是純粹的'XPath'解決方案,而你使用的工具可能不支持它... – Andersson

+0

嗨安德森,對不起我的錯誤,它的工作原理。非常感謝! –

-1

你應該能夠獲得這些URL的發言

descendant::link[contains(@href, 'ro_ro')] 

與文檔作爲當前節點

後代軸講述的XPath通過所有子節點看基本節點。 ::鏈接裝置僅選擇具有名稱鏈接和節點方括號內的表達式是指「只選擇那些節點,其href屬性包含「ro_ro'-

1

您可以用下面的公式

=importxml("https://example.org" ,"//link[@hreflang]/@href")