Webscraping:如何使用VBA从网页的下拉列表中选择值(选项)

Webscraping:如何使用VBA从网页的下拉列表中选择值(选项),vba,parsing,dropdown,frame,Vba,Parsing,Dropdown,Frame,在一个网站上,我可以登录,然后我试图从下拉菜单中选择一个值,但我无法获得任何包含该菜单的对象 值得关注的是,该页面似乎使用了三个框架窗口。下拉菜单位于其中一个窗口上 <label for="edit-multiple-form">...</label> <select id="edit-multiple-form" name="NNN" class="form-select form-contro

在一个网站上,我可以登录,然后我试图从下拉菜单中选择一个值,但我无法获得任何包含该菜单的对象

值得关注的是,该页面似乎使用了三个框架窗口。下拉菜单位于其中一个窗口上

<label for="edit-multiple-form">...</label>
<select id="edit-multiple-form" name="NNN" class="form-select form-control required ajax-processed"> == $0
   <option value selected="selected">- Select -</option>
   <option value="1"> OPTION1 </option>
   <option value="2"> OPTION2 </option>
   <option value="3"> OPTION3 </option>
</select>
::after
</div>
==========================================================================

 'Got a new HTML document after log on the the first page
    Dim IE3 As HTMLDocument
    Set IE3 = IEBrower.document
    
'then tried several methods to get the object using the following commands 
IE3.document.querySelector("option")

IE3.all.NNN.value   'NNN is the name of the dropdown menu object

IE3.getElementsByID("edit-multiple-form)

IE3.getElementsByClass("form-select form-control required ajaz-processed")
我能够抓取下拉菜单对象,但在@@ 怎么了? 任何帮助都将不胜感激

IE3.getElementById("edit-multiple-form")
这将返回selecthtml元素。然后,您可以通过以下方式进一步缩小范围:

Set elemSelect = IE3.getElementById("edit-multiple-form")
Set elemOption = elemSelect.getElementsByTagName("option")
然后你可以循环(对于elemOption.length-1,i=0)。请注意,getElementById中没有s,因为它始终只返回1项。此外,GetElementsByCass不是有效的方法,请改用GetElementsByCassName。
列出了可用方法的列表

谢谢!!我能抓住那个物体。但我仍然在elemOption上出错,所以我无法选择“选项1”。你认为问题出在哪里?如果不看到你的尝试,很难说。下次请张贴不起作用的代码。在手表窗口中检查电子。它返回选项HTML元素的集合,因此您必须选择要使用的元素。选中此处的elemOption(0),这应该是您的第一个元素。很抱歉,elemOption(0)将返回占位符项。使用电气选项(1)可选择1。或者,如果要动态检查,请使用从0到elemOption.length-1的for循环,然后检查elemOption(i).innerText
Set elemSelect = IE3.getElementById("edit-multiple-form")
Set elemOption = elemSelect.getElementsByTagName("option")