|
-
Oct 21st, 2009, 05:53 PM
#1
Thread Starter
Addicted Member
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
-
Oct 21st, 2009, 06:05 PM
#2
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.
-
Oct 22nd, 2009, 02:19 AM
#3
Thread Starter
Addicted Member
Re: Retrieving Data from html
The page is html, thats what i will always be seeing.
-
Oct 22nd, 2009, 02:34 AM
#4
Re: Retrieving Data from html
 Originally Posted by Teckniel
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?
-
Oct 22nd, 2009, 05:15 AM
#5
Thread Starter
Addicted Member
Re: Retrieving Data from html
Hello.
My program is a WinForms.
Inside my program i have a web browsercontroll
Regards Me
-
Oct 22nd, 2009, 05:27 AM
#6
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:
For Each element As HtmlElement In WebBrowser1.Document.Body.All If element.TagName = "input" Then 'you can access the element here 'e.g. we show its value in a messagebox for example MessageBox.Show(element.GetAttribute("value")) End If Next
-
Oct 22nd, 2009, 07:32 AM
#7
Thread Starter
Addicted Member
Re: Retrieving Data from html
 Originally Posted by Pradeep1210
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:
For Each element As HtmlElement In WebBrowser1.Document.Body.All
If element.TagName = "input" Then
'you can access the element here
'e.g. we show its value in a messagebox for example
MessageBox.Show(element.GetAttribute("value"))
End If
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
-
Oct 22nd, 2009, 08:00 AM
#8
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%" 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:
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("td") If element.GetAttribute("class") = "HeaderLabel2" Then MessageBox.Show(element.InnerText) Exit For End If Next
-
Oct 22nd, 2009, 08:05 AM
#9
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:
MessageBox.Show(WebBrowser1.Document.GetElementById("Element_Id_Here").InnerText)
or maybe the neater way:
vb.net Code:
Dim element As HtmlElement = WebBrowser1.Document.GetElementById("Element_Id_Here") MessageBox.Show(element.InnerText)
-
Oct 23rd, 2009, 06:32 PM
#10
Thread Starter
Addicted Member
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
-
Oct 24th, 2009, 05:33 PM
#11
Thread Starter
Addicted Member
Re: Retrieving Data from html
-
Oct 24th, 2009, 10:36 PM
#12
Re: Retrieving Data from html
vb.net Code:
WebBrowser1.Document.GetElementById("btStartOrder").click 'or WebBrowser1.Document.Forms("formname").InvokeMember("btStartOrder")
-
Oct 25th, 2009, 05:08 AM
#13
Thread Starter
Addicted Member
Re: Retrieving Data from html
 Originally Posted by Pradeep1210
vb.net Code:
WebBrowser1.Document.GetElementById("btStartOrder").click
'or
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
-
Oct 25th, 2009, 07:46 AM
#14
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
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
|