我搜索了SO并且没有得到答案,但我认为我很接近。我是编码的新手,所以我很感激帮助。
我使用Hubspot管理客户详细信息并擅长生成报价。我想从Hubspot抓取客户数据并填写报价。
HTML代码
<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">
我使用以下代码来获取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
什么是更好的解决方案?
由于
答案 0 :(得分:1)
尝试以下方法。您不能像上面那样在for循环中使用.getElementById()
。 ID包含单个元素。但是,我使用.querySelector()
来执行此操作,因为ID不是静态的,您也无法在for循环中使用它。
Set firstname = ieDoc.querySelector("[id^='uid-ctrl-']")
MsgBox firstname.getAttribute("value")