admin管理员组文章数量:1417070
=IMPORTXML(A2;"//div[@class='_b0ke8']/a/@href")
I'm trying to collect phone numbers via Excel (IMPORTXML
) and XPath.
But it only collects one (first) option. +7771128919 what am I doing wrong?
<div class="17zgb6" data-divider="true" data-divider-shifted="true">
<div class="before">
<div class="1ifozou">
<svg xmlns="; width="24" height="24" viewBox="0 9 24 24" fill="#0288ef">
<path d="M14 14.1 18.88 18.47 18.47 18.88 14 14.41 9.53 18.88 9.12 18.47 13.6 14 9.12 9.53 9.53 9.12 14 13.6 18.47 9.12 18.88 9.53z"></path>
</svg>
</div>
<div class="49xkir">
<div class="b0kes">
<a class="21cm9s8" href="tel:+7771128919" target="_blank">
<bdo dir="ltr">+7 701-211-89-19</bdo>
</a>
</div>
<div class="b0kes">
<a class="21cm9s8" href="tel:+77172485983" target="_blank">
<bdo dir="ltr">+7 (7172) 48-69-88</bdo>
</a>
</div>
<div class="b0kes">
<a class="21cm9s8" href="tel:+77022543764" target="_blank">
<bdo dir="ltr">+7 702-254-37-64</bdo>
</a>
</div>
</div>
</div>
</div>
</div>
//bdo[@dir='ltr']
I want to get all three numbers.
=IMPORTXML(A2;"//div[@class='_b0ke8']/a/@href")
I'm trying to collect phone numbers via Excel (IMPORTXML
) and XPath.
But it only collects one (first) option. +7771128919 what am I doing wrong?
<div class="17zgb6" data-divider="true" data-divider-shifted="true">
<div class="before">
<div class="1ifozou">
<svg xmlns="http://www.w3./2000/svg" width="24" height="24" viewBox="0 9 24 24" fill="#0288ef">
<path d="M14 14.1 18.88 18.47 18.47 18.88 14 14.41 9.53 18.88 9.12 18.47 13.6 14 9.12 9.53 9.53 9.12 14 13.6 18.47 9.12 18.88 9.53z"></path>
</svg>
</div>
<div class="49xkir">
<div class="b0kes">
<a class="21cm9s8" href="tel:+7771128919" target="_blank">
<bdo dir="ltr">+7 701-211-89-19</bdo>
</a>
</div>
<div class="b0kes">
<a class="21cm9s8" href="tel:+77172485983" target="_blank">
<bdo dir="ltr">+7 (7172) 48-69-88</bdo>
</a>
</div>
<div class="b0kes">
<a class="21cm9s8" href="tel:+77022543764" target="_blank">
<bdo dir="ltr">+7 702-254-37-64</bdo>
</a>
</div>
</div>
</div>
</div>
</div>
//bdo[@dir='ltr']
I want to get all three numbers.
Share Improve this question edited Feb 18 at 16:42 I.sh. 2,2212 gold badges13 silver badges44 bronze badges asked Feb 2 at 20:18 Villmark DeschanelVillmark Deschanel 112 bronze badges 2 |2 Answers
Reset to default 1Excel will only give you one result. A possible approach could be something like this:
Create VBA code like this:
Function GetXMLValues(xmlUrl As String, xPath As String) As String
Dim xml As Object
Set xml = CreateObject("MSXML2.DOMDocument")
xml.async = False
xml.Load xmlUrl
Dim nodeList As Object
Set nodeList = xml.SelectNodes(xPath)
Dim i As Integer
Dim results As String
results = ""
For i = 0 To nodeList.Length - 1
results = results & nodeList.Item(i).Text & vbNewLine
Next i
GetXMLValues = results
End Function
And use it in Excel like this:
=GetXMLValues(A2, "//div[@class='_b0ke8']/a/@href")
Your sample isn't well formed but since it seems to be using namespaces, try something like this on your actual xml:
//*[local-name()='div'][@class='b0kes']//*[local-name()='a']/@href
and see if it works.
本文标签: How to get multiple Href from XPathStack Overflow
版权声明:本文标题:How to get multiple Href from XPath? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745258166a2650227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
b0kes
instead of_b0ke8
? – Fravadona Commented Feb 2 at 22:29RegExp
(local copy), or web scrape the numbers(website). – nikitimi Commented Feb 3 at 9:53