|
-
May 24th, 2009, 01:39 PM
#1
[RESOLVED] Using Webbrowser control with Text Document
I'm trying to pull specific information from a website using the webbrowser control. Using something like this:
vb.net Code:
If chkSears.Checked And chk46V5100.Checked = True Then
WebBrowser1.Navigate("http://www.sears.com/shc/s/p_10153_12605_05772639000P?vName=Computers+%26+Electronics&cName=Televisions&sName=Flat+Panel")
While Not WebBrowser1.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
End While
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
For Each DivTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
Dim s = DivTag.GetAttribute("className")
If s IsNot Nothing AndAlso s = "pricing" Then
TextBox1.Text = (DivTag.OuterText)
End If
Next
End If
End If
When doing a search (ctrl+f) through the HTML, I only find one span tag that has its class name as pricing. But, when I run the code, I get a completely different price. I think the problem is that the page might be linked to another or something along those lines.
So, I decided to try a different approach. I wanted to download the HTML into a text file and use the same approach. It loads the information into the webbrowser control, which is good. But it doens't pull the info like it does on a website.
vb.net Code:
If chkSears.Checked And chk32S5100.Checked = True Then
Dim wc As New System.Net.WebClient()
wc.DownloadFile("http://www.sears.com/shc/s/p_10153_12605_05772639000P?vName=Computers+%26+Electronics&cName=Televisions&sName=Flat+Panel", "C:\file.txt")
WebBrowser1.Navigate("C:\file.txt")
For Each DivTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
Dim s = DivTag.GetAttribute("className")
If s IsNot Nothing AndAlso s = "pricing" Then
txt32S5100sears.Text = (DivTag.OuterText)
End If
Next
End If
That's the code I'm trying to use.
If anyone has any suggestions or another method, I would appreciate it.
Thanks
Last edited by weirddemon; May 24th, 2009 at 01:42 PM.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
May 25th, 2009, 09:52 AM
#2
Re: Using Webbrowser control with Text Document
Would I have to use any of the streamreader methods?
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
May 25th, 2009, 10:49 AM
#3
Addicted Member
Re: Using Webbrowser control with Text Document
i don't really understand that much about web browser, but i made my own way code and it seems working, i am sure there are better and easier ways, but i think mine worked too and you can use it, just copy and paste.
PHP Code:
Dim getnumber6 As Int16 = 0
Dim its6 As Int16
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each DivTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
'look weirddemon this is what i did
'Always price number shows the sixth time. When it goes through the loop it shows at the sixth time,
'so what i did, i made it count, and until its in the sixth time,it takes whatever is there. Now you can change it
' to the forth , fifth whatever you like, and it will pick the item at the forth or fifth loop.
' by the way if you more help let me know, because i am also using web browser. I am learning it for the first
' time too
its6 = getnumber6 + 1
getnumber6 = its6
If its6 = 6 Then
MessageBox.Show("Price is: " & DivTag.InnerText)
End If
' End If
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("www.sears.com/shc/s/p_10153_12605_05772639000P?vName=Computers+%26+Electronics&cName=Televisions&sName=Flat+Panel")
End Sub
look weirddemon this is what i did
Always price number shows the sixth time. When it goes through the loop it shows at the sixth time,so what i did, i made it count, and until its in the sixth time,it takes whatever is there. Now you can change it to the forth , fifth whatever you like, and it will pick the item at the forth or fifth loop.by the way if you more help let me know, because i am also using web browser. I am learning it for the first time too
-
May 25th, 2009, 12:58 PM
#4
Re: Using Webbrowser control with Text Document
Thanks, ammar555, for the help.
Your code works, but the 6th tag does not pull the information I need. When I use the 6th tag I get, "(Be the first to rate this item)".
I went through about 30 tags and wasn't able to get the info.
Is there a way to loop through the span tags that contain the Class name "prices"?
This would decrease the amount of tags that I'd need to loop through.
Thanks
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
May 25th, 2009, 01:16 PM
#5
Addicted Member
Re: Using Webbrowser control with Text Document
so let me get it clear first
The Price worked right? it showed the price?
now tell me the information you want to get ? which one ?
here is what i get when it loops through all the tags, tell me which one of the following and i will make the code.
Sears
Recently Viewed Shopping Cart 0 items ($0.00)
Shopping Cart 0 items ($0.00)
Shopping Cart 0 items ($0.00)
Computers & Electronics Televisions > Flat Panel Share This Item Print
Sony Bravia® 32 in. (Diagonal) Class 1080p LCD HD Television Item# 05772639000 Model# KDL32S5100 (Be the first to rate and review this item)
$799.99
Delivery
Pick Up
Delivery
Pick Up
Read more specifications
Read more specifications
Costs below are for the ZipCode
Change your Zip code :
Number of reviews:
Number of reviews with ratings & comments:
Number of reviews with ratings-only:
Read existing product reviews
Write a Review
Write a Review
Here is your chance to tell others what you think of this product. Please be sure to focus on the features of this product and why you like or dislike them.
More Review Guidelines & Tips
The email addresses you entered are not the same. Please check your address and try again.
Email Address:
Confirm:
Your email address will not be displayed in the review, we will use it to update you on the status of your review.
Loading
Shop Gifts(View all)
Shop Appliances(View all)
Shop Automotive(View all)
Shop Baby(View all)
Shop Clothing(View all)
Shop Electronics & Computers(View all)
Shop Music, Movies & Games(View all)
Shop Office Products(View all)
Shop Outdoor Living
(View all)
Shop Fitness & Sports(View all)
Shop For the Home(View all)
Shop Health & Wellness(View all)
Shop Jewelry & Watches(View all)
Shop Lawn & Garden(View all)
Shop Shoes(View all)
Shop Tools(View all)
Shop Toys & Games(View all)
Shop Beauty(View all)
Shop Home Services(View all)
Shop Books(View all)
look i used this code and i got all the above, so now try your best to get the one that you want.
Code:
For Each DivTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
'GET CLASS NAME OF GIVEN DIV TAG
Dim s = DivTag.GetAttribute("class")
TextBox1.AppendText(DivTag.Parent.OuterText & vbCrLf)
Next
use this if you want to take out specific info
If DivTag.Parent.OuterText.StartsWith("Whatever you want") = True Then
textbox1.Text = (DivTag.OuterText)
-
May 25th, 2009, 01:54 PM
#6
Re: Using Webbrowser control with Text Document
I'm not sure what happened earlier. I tried the code again, but I used 7 and it pulled it just fine.
I need to do this for several different items. So, how did you pull all of the tags? I'd want to do this so I can easily identify the tags .
Thanks
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
May 25th, 2009, 02:43 PM
#7
Re: Using Webbrowser control with Text Document
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
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
|