|
-
Sep 6th, 2010, 10:51 AM
#1
Thread Starter
Member
HtmlAgilityPack
Im having a hard time finding tutorials for the HtmlAgilityPack, all of them are for c#, so im having to use c# code and convert it to vb.
Here is the my code, im still getting errors with the 3rd line:
Code:
Dim doc As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument
doc.Load("http://www.yellowpages.ca/search/si/1/Estheticians/Calgary+AB ")
For each HtmlNode in link doc.DocumentNode.SelectNodes("@'//span[@class=''listingTitle'']")
Dim content As String
content = link.InnerText
Next
And here is the c# code that im converting from:
Code:
HtmlDocument doc = new HtmlDocument();
doc.Load("http://www.yellowpages.ca/search/si/1/Estheticians/Calgary+AB ");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes(@"//span[@class=""listingTitle"]"))
{
string content = link.InnerText;
}
-
Sep 6th, 2010, 11:03 AM
#2
Frenzied Member
Re: HtmlAgilityPack
It must be like this
For Each link as HtmlNode in doc.Docu....
-
Sep 6th, 2010, 11:20 AM
#3
Thread Starter
Member
Re: HtmlAgilityPack
Thanks, that seems to have worked. One last thing please, How can I set the retrieved text into a textbox on my form?
Here is what I tried:
Code:
Dim content As String
Dim doc As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument
doc.Load("http://www.yellowpages.ca/search/si/1/Estheticians/Calgary+AB ")
For Each link As HtmlNode In doc.DocumentNode.SelectNodes("@'//span[@class=''listingTitle'']")
content = link.InnerText
Next
TextBox1.Text = content
But im getting "Variable 'content' is used before it has been assigned a value, a null reference exception could result at runtime." Im guessing I need to do some kind of If statement, but im not sure how.
-
Sep 6th, 2010, 11:46 AM
#4
Frenzied Member
Re: HtmlAgilityPack
No Issues,Thats only a Warning but not an Error
you can even clear it by using this
Dim content as String = ""
-
Sep 6th, 2010, 04:41 PM
#5
Thread Starter
Member
Re: HtmlAgilityPack
Ok, I fixed my above problem I believe, but now I have a new problem:
Code:
Dim content As String
Dim doc As New HtmlDocument
doc.LoadHtml("http://www.yellowpages.ca/search/si/1/Estheticians/Calgary+AB ")
For Each link As HtmlNode In doc.DocumentNode.SelectNodes("@'//span[@class=''listingTitle'']")
content = link.InnerText
TextBox1.Text = content
Next
I replaced DocumentElement with DocumentNode in the 4th line because vb didnt understand DocumentElement. When the app runs this line it gives me an error:
"XPath exception was unhandled.
Expression must evaluate to a node-set."
Last edited by Datadayne; Sep 6th, 2010 at 04:46 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|