Reputation: 89
Using this search URL for Bing:
I need to get, from the class, and only from the class "iusc" the href attribute for every picture returned by bing on the search.
The code base I use is this:
For Each link As HtmlAgilityPack.HtmlNode In htmlDoc.DocumentNode.SelectNodes("//a[@href]")
debug.Print(link.GetAttributeValue("href", ""))
Next
But it returns the "murl" attribute, not the "href".
How to get the href then?
Upvotes: 1
Views: 273
Reputation: 6718
The problem was that xpath expression and also the way the document is loaded from the web which results in an empty document. Try this:
Dim website As New HtmlWeb()
Dim doc As HtmlDocument = website.Load(url)
Dim links = doc.DocumentNode.SelectNodes("//a[contains(@class,'iusc')]")
For Each link In links
Dim href As String = link.GetAttributeValue("href", "")
Debug.Print(href)
Next
Take into account that Debug.Print() send output to different windows depending on how you have configured VS. If you don't see anything, please debug and inspect href value.
Upvotes: 1