I have searched SO and haven't been able to get an answer but I think I am close. I am new to coding so I appreciate the help.
I use Hubspot manage customer details and excel to produce quotes. I want to scrape customer data from Hubspot and have it populate the quote.
The HTML code
<input type="text" property="PropertyRecord { "calculated": false,
;createdUserId": null, "defaultValue": undefined,
;deleted": null, "description": "A contact's first
name", "displayMode": "current_value",
;displayOrder": 0, "externalOptions": false,
;favorited": true, "favoritedOrder": 0,
;fieldType": "text", "filterName":
"", "formField": true, "groupName":
;contactinformation", "hidden": false,
;hubspotDefined": true, "label": "First Name",
;mutableDefinitionNotDeletable": true, "name":
;firstname", "numberDisplayHint": null,
;objectType": undefined, "options": List [],
;optionsAreMutable": null, "placeholder": "",
;prospectType": null, "readOnlyDefinition": true,
;readOnlyValue": false, "referencedObjectType": null,
;searchable": true, "showCurrencySymbol": null,
;sortable": true, "textDisplayHint": null,
;type": "string", "updatedUserId": null }"
value="Jonnevie" id="uid-ctrl-54" data-field="firstname" data-selenium-
test="property-input-firstname" autocomplete="off" class="form-control
private-form__control private-form__control--inline isInline">
I am using the following code to scrape and getting a Run Rime Error 424
Dim ie As InternetExplorer
Dim ieDoc As HTMLDocument
Dim firstname As Object
Dim url As Variant
Dim ID As Variant
Dim Content As String
Dim i As Integer
Set ieApp = New InternetExplorer
ieApp.Visible = 1
url = "https://app.hubspot.com/sales/3425759/contact/379701/?interaction=note"
ieApp.navigate url
Do While ieApp.Busy:
DoEvents: Loop
Do Until ieApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Dim ele As Object
Set ieDoc = ieApp.document
For Each ele In ieDoc.getElementById("uid-ctrl-8")
Debug.Print (ele.text)
Next ele
ieApp.Quit
What would be a better solution?
Thanks
Try the below approach. You can't use .getElementById()
in a for loop as you did above. The ID contains a single element. However, I used .querySelector()
to do the trick cause the ID's are not static and you can't use it in a for loop either.
Set firstname = ieDoc.querySelector("[id^='uid-ctrl-']")
MsgBox firstname.getAttribute("value")