I’m scraping a website. There’s a TD where the first child node is an H3 with an innertext of “Directs”. In the TD the other children (besides the H3) are the links. I know XPath is perfectly capable of just returning the A tag children from a TD that also contains an H3 with an innertext of “Directs”, I just can’t seem to get it right. The ugly work-around I came up with is the following, but I want to learn the best XPath method:
For Each thisH3 As HtmlNode In Doc.SelectNodes("//h3")
If thisH3.InnerText = "Directs" Then
For Each nChild As HtmlNode In thisH3.ParentNode.ChildNodes
If nChild.Name = "a" Then
Debug.Print(nChild.InnerText)
End If
Next
End If
Next
Use this XPath to retrieve all
aintdwhich haveh3with valueDirects: