【发布时间】:2015-10-15 11:23:10
【问题描述】:
我希望在 primenow.amazon.co.uk 上输入邮政编码提交表单并将结果粘贴到 excel 中
Sub PostCode_Delivery_Short()
Dim ie As Object
Dim form As Variant, button As Variant
'add the “Microsoft Internet Controls” reference in your VBA Project indirectly
Set ie = CreateObject("InternetExplorer.Application")
'Input box for postcode
Postcode = InputBox("Enter Postcode")
With ie
.Visible = True
.Navigate ("primenow.amazon.co.uk")
'we ensure that the web page downloads completely before we fill the form automatically
Application.Wait (Now + TimeValue("00:00:04"))
'assigning the vinput variables to the html elements of the form
ie.Document.getElementsByClassName("availability__form__instructions__heading")(0).innertext = Postcode
'accessing the button via the form
Set form = ie.Document.getElementsByClassName("form")
Set button = form(0).onsubmit
form(0).submit
End With
'cleaning up memory
Set ie = Nothing
End Sub
我正在努力解决的是元素 ID(我认为),我不断收到运行时“对象变量错误或未设置块变量”。
【问题讨论】:
标签: excel vba forms web-scraping screen-scraping