Visual Basic & HTML Agility Pack

html-agility-pack visual-studio-2012


I'm trying to pull the title of page from yahoo

I ask user for Symbol is creates the url:

The program works great when I load a local .html of the same page...

Here 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 any idea on how I could get this work? I eventually want to pull stock prices etc...

I'm also down for learning an easier way to do what I am trying to accomplish. Instead of using KeyValuePair etc... Just something I finally got to work on another SO question.


6/22/2013 4:17:18 AM

Popular Answer

When pulling a web url, you should be using the HtmlWeb class to load the documents. The HtmlDocument.Load method can only read from local files (or streams). You're probably seeing an error along the lines of "cannot read from url" or "url not supported".

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