I have a script that parses an HTML page to find an element with a specified ID. What I need is to get the parent node (actually, I need to go 2 parent nodes up) so that I can either cycle through all the links in the table to find the link I want OR so I can parse the HTML of the entire table to find the link I want.
Sub testmacro()
'Constants
Const pdlID = "Id of the element"
Const urlbase = "what ever url"
'containers
Dim web As Object
Dim prompt As String
Dim pdlTbl As Object
Dim pdllink As Object
'Get URL
prompt = InputBox("Paste the URL here: ", "URL")
'create IE instance
Set web = CreateObject("InternetExplorer.Application")
web.Visible = True
web.Navigate prompt
Do While web.Busy Or web.ReadyState <> 4
DoEvents
Loop
'get IE document
Set pdlTbl = web.Document
Set pdlTbl = pdlTbl.getelementbyid(pdlID)
'Get parent node of element
web.Quit
Set web = Nothing
End Sub
Ive tried to find information on getting parent nodes but I couldn't so any help on locating the parent nodes would be great.
Additionally, I was having major issues trying to cycle through elements in the document. I grabbed many many code samples from this site and they were all returning the same errors "Object does not support this method" or something along the lines. It was highlighing the first line in loops that looked like this.
for each a in pdltbl
next a
This error came out no matter which tag I tried to use or the type of element I looked through (pdlID refers to a TD element for reference)
Basically, I just want to be able to search through the table to find a link with a specific URL (based off the url in prompt)
Set pdlTbl = pdlTbl.getelementbyid(pdlID)
Set parentParent = pdlTbl.parentElement.parentElement
to get all the links in a table:
Set allLinks = tbl.getElementsByTagName("a")
For Each a in allLinks
'...
Next a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With