Visual Basic & HTML Agility Pack

html-agility-pack visual-studio-2012


I'm attempting to get the page's title from Yahoo.

I request a symbol, and it generates the following url:

When I load a local copy of the identical page in.html, the software runs flawlessly.

This is my code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim symbol As String, htmldoc As New HtmlDocument
    symbol = TextBox3.Text
    Dim items = htmldoc.DocumentNode.SelectNodes("//head/title").Select(Function(node) New KeyValuePair(Of String, String)(node.InnerText, node.InnerText))

    For Each item As KeyValuePair(Of String, String) In items

End Sub

Anyone have suggestions on how I may make this work? I want to ultimately pull stock prices, etc.

I'm also open to discovering a simpler approach to complete the task at hand. In place of KeyValuePair etc. Just something I finished working on a different SO question.


6/22/2013 4:17:18 AM

Popular Answer

If you want to retrieve a site address, you should use theHtmlWeb to load the docs in class. TheHtmlDocument.Load technique is limited to reading from local files (or streams). You're most likely seeing a message that says "url not supported" or "cant read from url."

Dim url = ""
Dim web = new HtmlWeb
Dim doc = web.Load(url)
Dim titleNode = doc.DocumentNode.SelectSingleNode("/html/head/title")
Dim title As String
If titleNode IsNot Nothing Then
    title = titleNode.InnerText
End If
6/21/2013 3:53:45 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow