SomeOneMore
SomeOneMore

Reputation: 89

Getting href from Bing using HtmlAgilityPack

Using this search URL for Bing:

http://www.bing.com/images/search?scope=images&sp=-1&pq=ferrari&sc=9-3&sk=&cvid=E471F1335E6A48C897DB5CEE745F51E1&q=ferrari&qft=+filterui:imagesize-large&FORM=R5IR3%22

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

Answers (1)

Daniel Manta
Daniel Manta

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

Related Questions