刮在亚马逊总理现在邮编input

我正在寻找在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(我认为),我不断得到一个运行时“对象variables错误或块variables未设置”。

getElementsByName返回一个集合,而不是一个单一的元素,所以尝试像这样:

 ie.Document.getElementsByName("prime-now-input")(0).innertext = Postcode 

另外编辑

 .Document.getElementsByTagName("availability__form__instructions__heading") 

我很确定这个标签名没有HTML元素;-)也许你的意思是getElementsByClassName()

EDIT2:这是您需要input邮编的元素(使用.Value,而不是.innerText)

 <input type="text" placeholder="Enter a postcode to see if we deliver to your area ..." maxlength="9" data-reactid=".0.1.0.1.1.0.0.1.0.0"> 

我的IE版本甚至不提供input,所以我不能提供更多的build议。