Link to home
Start Free TrialLog in
Avatar of karthik80c
karthik80cFlag for United States of America

asked on

Run time error on getElementsById() function in VBA script

Error:
Runtime error 438,
Object doesn't support this property or method

DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim topic As Variant
topic = Doc.getElementsById("description")(0).innerText

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

not too sure but you can try:

topic = Doc.getElementById("description")(0).innerText

?
Please post a complete and concise example.

What does Doc.getElementsById("description") return, if it returns anything at all?
Avatar of karthik80c

ASKER

Need to scrap the text in h3 tag

<div id="description">
<h3>The Key Industrial Park - 18 Prime Lots with EastLink Exposure</h3> 
<p class="body">Frasers Property is pleased to offer 18 allotments from 1,093m² to 3.681ha as part of their stage 4 &amp; 5 release.<br><br>• 31 Allotments already sold<br><br>• Superb opportunity for owner-occupiers and developers<br><br>• Allotments with EastLink access like this are increasingly difficult to find<br><br>• Join other big names – Miele, BIC, TriMas, Tyres4U, Early Settler, Sealy, Victoria Station, Rinnai<br><br>Contact the appointed agents for a copy of the Information Memorandum and Plan of Subdivision.</p></div>

Open in new window

I cant scrap it with the <h3> tag name, because there are 8 <h3> tags in a page. so tried to get the text with id. But It returns "[object HTMLMetaElement]"
VB Code:
Sub PropertyURLL()
Dim IE As New InternetExplorer
IE.navigate "http://www.realcommercial.com.au/property-retail-qld-kooralbyn-501463555"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.document
Dim adtop As String
Dim sDD As String
sDD = Trim(Doc.getElementsByTagName("h1")(0).innerText)
Dim topic As Variant
topic = Doc.getElementById("description")
Dim status As Variant
status = Doc.getElementsByClassName("saleType")(0).innerText
Dim body As Variant
body = Doc.getElementsByClassName("body")(0).innerText
Dim price As Variant
price = Doc.getElementsByClassName("price ellipsis")(0).innerText

MsgBox topic

 Dim dtInspDate As Variant
 Dim dtInspTime As Variant
 Dim aTextTmp As Variant, aInspDate As Variant
aInspDate = Split(sDD, ", ")
dtInspDate = aInspDate(1)
dtInspDe = aInspDate(0)
Dim Poost As String
Poost = Right(sDD, 4)
Dim suburb As String
suburb = dtInspDate
Title = dtInspDe
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial