Results 1 to 7 of 7

Thread: [RESOLVED] Using Webbrowser control with Text Document

  1. #1

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Resolved [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:
    1. If chkSears.Checked And chk46V5100.Checked = True Then
    2.             WebBrowser1.Navigate("http://www.sears.com/shc/s/p_10153_12605_05772639000P?vName=Computers+%26+Electronics&cName=Televisions&sName=Flat+Panel")
    3.             While Not WebBrowser1.ReadyState = WebBrowserReadyState.Complete
    4.                 Application.DoEvents()
    5.             End While
    6.             If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
    7.                 For Each DivTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
    8.                     Dim s = DivTag.GetAttribute("className")
    9.                     If s IsNot Nothing AndAlso s = "pricing" Then
    10.                         TextBox1.Text = (DivTag.OuterText)
    11.                     End If
    12.                 Next
    13.             End If
    14.         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:
    1. If chkSears.Checked And chk32S5100.Checked = True Then
    2.             Dim wc As New System.Net.WebClient()
    3.             wc.DownloadFile("http://www.sears.com/shc/s/p_10153_12605_05772639000P?vName=Computers+%26+Electronics&cName=Televisions&sName=Flat+Panel", "C:\file.txt")
    4.             WebBrowser1.Navigate("C:\file.txt")
    5.             For Each DivTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("span")
    6.                 Dim s = DivTag.GetAttribute("className")
    7.                 If s IsNot Nothing AndAlso s = "pricing" Then
    8.                     txt32S5100sears.Text = (DivTag.OuterText)
    9.                 End If
    10.             Next
    11.         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

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  2. #2

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Using Webbrowser control with Text Document

    Would I have to use any of the streamreader methods?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3
    Addicted Member
    Join Date
    May 2009
    Posts
    134

    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.ObjectByVal e As System.EventArgsHandles 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 timeWhen 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

  4. #4

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    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

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Addicted Member
    Join Date
    May 2009
    Posts
    134

    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)

  6. #6

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    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

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7

    Thread Starter
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Using Webbrowser control with Text Document

    I figured it out.

    Thanks
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote 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
  •  



Click Here to Expand Forum to Full Width