Results 1 to 14 of 14

Thread: Retrieving Data from html

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Post Retrieving Data from html

    Hello.
    How are you all doing?
    I have finally left vb6 behind and moved to vb8
    But i'm having a problem, I dont know on how to retrieve the data of all the input fields on my temp webpage: link.

    Could anyone help me out?


    Friendly Regards
    Me

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Retrieving Data from html

    Is this ASP.NET or WinForms?

    Just in case it is ASP.NET, you would get the values of all controls on postback in your server-side code.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Re: Retrieving Data from html

    The page is html, thats what i will always be seeing.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Retrieving Data from html

    Quote Originally Posted by Teckniel View Post
    The page is html, thats what i will always be seeing.
    That wasn't the question. Is your project an ASP.NET project or a WinForms project? Are we talking about displaying a web page in a WebBrowser control or is your application itself the web page?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Re: Retrieving Data from html

    Hello.
    My program is a WinForms.
    Inside my program i have a web browsercontroll

    Regards Me

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Retrieving Data from html

    You can loop thru the elements in the WebBrowser.Document and if you find that it is an element of type INPUT, get its value (or whatever you want).

    e.g.
    (not tested code)
    vb.net Code:
    1. For Each element As HtmlElement In WebBrowser1.Document.Body.All
    2.     If element.TagName = "input" Then
    3.         'you can access the element here
    4.         'e.g. we show its value in a messagebox for example
    5.         MessageBox.Show(element.GetAttribute("value"))
    6.     End If
    7. Next
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Re: Retrieving Data from html

    Quote Originally Posted by Pradeep1210 View Post
    You can loop thru the elements in the WebBrowser.Document and if you find that it is an element of type INPUT, get its value (or whatever you want).

    e.g.
    (not tested code)
    vb.net Code:
    1. For Each element As HtmlElement In WebBrowser1.Document.Body.All
    2.     If element.TagName = "input" Then
    3.         'you can access the element here
    4.         'e.g. we show its value in a messagebox for example
    5.         MessageBox.Show(element.GetAttribute("value"))
    6.     End If
    7. Next
    Ok thanks that works, just need to modify it for my usage

    My next question is how can I obtain this (750416551) from the webpage, note that the number will be different each time.

    Regards Me

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Retrieving Data from html

    From what I see from the source of that page, this is the line that shows that number:
    Code:
    <td class="HeaderLabel2" valign="center" width="45&#37;" align="right">Borg Fred (750416551)</td>
    This (or any of its parents) do not have an ID tag. So there is no sure way to identify this element. But looking at the whole document I find that this is the only element using the class="HeaderLabel2" style. So what we can do is get all the <td> tags and then check each one of them if its class is "HeaderLabel2".

    So you can try something like this to get it:
    (not tested code)
    vb.net Code:
    1. For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("td")
    2.     If element.GetAttribute("class") = "HeaderLabel2" Then
    3.         MessageBox.Show(element.InnerText)
    4.         Exit For
    5.     End If
    6. Next
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Retrieving Data from html

    If you are the developer of this page or can get the source altered, I would recommend putting an ID tag with whatever elements you need to reference to. This way you do not need to loop thru all the elements or use any other non-reliable method to reference it.

    e.g. If that element had an ID tag, we could have simply done it in one line and with much more confidence:
    vb.net Code:
    1. MessageBox.Show(WebBrowser1.Document.GetElementById("Element_Id_Here").InnerText)

    or maybe the neater way:
    vb.net Code:
    1. Dim element As HtmlElement = WebBrowser1.Document.GetElementById("Element_Id_Here")
    2. MessageBox.Show(element.InnerText)
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Re: Retrieving Data from html

    Hello.
    I have perfect implemented the readout of the web page in my program.
    What i did was:: I cached it all in a public array(the stuff I wanted),
    That way i can access it everywhere when needed and also stored it in my database for later usage.

    Pradeep1210: If you are the developer of this page or can get the source altered, I would recommend putting an ID tag with whatever elements you need to reference to. This way you do not need to loop thru all the elements or use any other non-reliable method to reference it.
    Dear Pradeep: i do not have access to the source code.

    But I have solved the readout of the client number: 750416551

    What I'm creating is a new version of a very old outdated program
    The problem is i work as a subcontractor for a company, that company use a browser system to control everything.
    For example: When i arrive @ a client i have to click the 'Start order' Button.

    And this is where my next question comes in.
    Is it possible to do that automatically for me, like if i click a command button i click the start order button?

    The page I have link't is saved from the webbrowser during work
    Its 1 of the many i have to decode

    And thanks for are the help so far, this is why I always come to this forum when i need aide!
    Last edited by Teckniel; Oct 23rd, 2009 at 06:47 PM. Reason: Added More Info

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Re: Retrieving Data from html

    bump

  12. #12
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Retrieving Data from html

    vb.net Code:
    1. WebBrowser1.Document.GetElementById("btStartOrder").click
    2.  
    3. 'or
    4.  
    5. WebBrowser1.Document.Forms("formname").InvokeMember("btStartOrder")
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belgium
    Posts
    167

    Re: Retrieving Data from html

    Quote Originally Posted by Pradeep1210 View Post
    vb.net Code:
    1. WebBrowser1.Document.GetElementById("btStartOrder").click
    2.  
    3. 'or
    4.  
    5. WebBrowser1.Document.Forms("formname").InvokeMember("btStartOrder")
    Thanks for all the help Pradeep.
    Do you know any good link to a manuel of the WebBrowser1.Document controll?

    Regards Me

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Retrieving Data from html

    Google around for "Document Object Model" and "DOM Scripting". I'm sure you would find many good links.

    Also have a look at this wikipedia article:
    http://en.wikipedia.org/wiki/Document_Object_Model
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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