【发布时间】:2019-07-16 07:12:39
【问题描述】:
我正在尝试从位于 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 的输入框中输入我的电子表格中的域名 第二步:点击“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
结束子
【问题讨论】:
标签: excel vba dom excel-2010 internet-explorer-11