Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get the value of an element in a web page 1

Status
Not open for further replies.

sarcus25

Programmer
Apr 14, 2005
27
0
0
Hi I'm trying to get the value of a element nested inside an object using the webbrowser control. How would I got about doing this. Thanks in advance.

The html code I'm trying to extract the value from is as follows:

<OBJECT>

<PARAM name="SRC" VALUE="Value To be extracted">

</OBJECT>
 
How much do you know about the DOM (document object model)? You can access the DOM for a page in the webbrowser control using
Code:
[i]wbBrowserCtl[/i].document.body.[i]attribute[/i]


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Also, check into:
getElementById("id")
And
getElementsByName("name")
And possibly:
getElementsByTagName("tag")

Note that GetElementById returns a single Element...
But, the other 2 functions return Collections (Arrays of Elements) which you will have to specify which you want to use...
Such As...
Code:
X = wb.document.body.getElementsByName("SRC")[b](0)[/b].value

However, if the element is not found, the .value will result in an "Object Not Set" error, so it is better to use:
Code:
[b]Dim E as object
Set E =[/b] wb.document.body.getElementsByName("SRC")[b](0)[/b]
[b]If Not E Is Nothing Then[/b] X = [b]E.[/b]value

Or you could be lazy (like me most of the time :p)
Code:
[b]On Error Resume Next[/b]
  X = wb.document.body.getElementsByName("SRC")[b](0)[/b].value
[b]On Error Goto 0[/b]

For Further Reference:

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Thanks for the info, it helped me alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top