我正在尝试从位于https://www.godaddy.com/domain-value-appraisal
的GoDaddy评估服务中自动检索域名价值我已经手动完成了近400次操作,但这非常繁琐,容易出错,并且需要花费很多时间。我认为如果可以在Excel 2010中创建VBA函数,则可以使Internet Explorer自动化。我要的机器上的IE版本是IE 11。
我尝试了来自各个站点的几个不同的建议示例,包括StackOverflow.com,但没有取得任何进展。我被困在如何用电子表格中的域名填充文本框。因此,我所做的只是硬编码要测试的域名。我可以整理一下将在400行之后循环的代码,但是现在我正试图让其中的一个工作。.我正在用我认为的IE DOM弄乱一些东西。
我什至不能确定我其余的步骤是否正确编码。下面是该代码的最新版本。
我要自动化三个步骤: 步骤1:将电子表格中的域名输入https://www.godaddy.com/domain-value-appraisal的输入框中 步骤2:点击“ GoValue”按钮 步骤3:将估算值返回到电子表格中的单元格。
代码在下面。如果有人能识别我做错了什么以及如何正确进行,谢谢。
Sub Try3()
Dim IE As New InternetExplorer
Dim doc As HTMLDocument
Dim objDomainIn As HTMLInputElement
Dim objGoButton As HTMLButtonElement
Dim objValueOut As HTMLSpanElement
IE.Visible = True
'GO TO THE GODADDY VALUATION PAGE
IE.Navigate "https://www.godaddy.com/domain-value-appraisal"
'WAIT FOR THE PAGE TO LOAD
Do
DoEvents
Loop Until IE.LocationName = "Free Domain Value and Appraisal Tool | What is your domain worth? - - GoDaddy"
Set doc = IE.document
'I WOULD LIKE TO DO THE FOLLOWING STEPS FOR SEVERAL HUNDRED DOMAIN NAMES. BUT FOR THIS EXAMPLE, HERE IS ONE OF NAMES:
'1) insert the domain name into the "domainToCheck" textbox
'2) click the "GoValue™" button
'3) scrape the Estimated Value from the result page
'SO TRANSLATING THOSE STEPS TO VBA I TRIED:
'STEP 1)
'THE INPUT TEXTBOX ON THE FORM:
'<input name="domainToCheck" class="domain-name-input searchInput form-control" aria-label="Enter a domain name" type="text" placeholder="Enter a domain name" value="">
Set objDomainIn = doc.all.getElementsByName("domainToCheck") '<----**** I AM STUCK HERE ***
objDomainIn.Value = "MPGBooster.com"
'STEP 2)
'BUTTON THAT NEEDS TO BE AUTOMATICALLY CLICKED (I added carriage returns because it was very long):
'<button class="btn btn-primary submit "
' type="Submit"
' data-eid="gce.sales.domain-value-appraisal.domain_search_marquee.domain_search_marquee_lp_module.button"
' data-creative-slot="e6a02371-14a2-4a21-b444-4aa0ae01b3b7"
' data-creative-name="domain-value-appraisal/Domain Search Marquee LP Module/Domain Search Block/Primary CTA"
' data-promo-name="domain_search_marquee.domain_search_marquee_lp_module.button8b002669-c11d-4913-881e-fe39fce24eab"
' data-promo-id="gce.sales.domain-value-appraisal."
' data-schema="add_promotion" data-tdata="module_id,e6a02371-14a2-4a21-b444-4aa0ae01b3b7^block_id,8b002669-c11d-4913-881e-fe39fce24eab^block_path,/ComponentSettings/GoDaddy/Sales/domain-value-appraisal/Domain Search Marquee LP Module/Domain Search Block/Primary CTA^campaign_name,^redpntcn,^redpntrid,^redpntcid,^redpntsn,^redpntrc,"
' value="GoValue™">GoValue™</button>
'CLICK "GOVALUE" BUTTON TO GET DOMAINS VALUE
Set objGoButton = doc.document.getElementsByClassName("input-group-btn")
objGoButton.click
'STEP 3)
'THE RETURNED HTML SHOWING THE DOMAIN ESTIMATED VALUE
'<span class="dpp-price price"><strong>$1,426</strong></span>
Set objValueOut = doc.getElementsByClassName("dpp-price price")
MsgBox "MPGBooster.com valued at: " & objValueOut.innerText
'CLEAN UP OBJECTS
IE.Quit
Set IE = Nothing
结束子
答案 0 :(得分:2)
首先,getElementsByName是Document对象的属性。其次,它返回一个从0开始的元素集合。因此,请尝试以下操作...
Set objDomainIn = doc.getElementsByName("domainToCheck")(0)
objDomainIn.Value = "MPGBooster.com"
或者,您可以使用querySelector方法...
Set objDomainIn = doc.querySelector("input[name='domainToCheck']")
objDomainIn.Value = "MPGBooster.com"
请注意,getElementsByClassName还返回基于0的元素集合。因此,您需要相应地建立索引。