尝试使用VBA代码获取HTML Dropbox(第2步)

时间:2019-02-10 05:09:46

标签: html vba web-scraping internet-explorer-11 dropdownbox

试图从vba代码中获取一个保管箱,但是在保管箱打开之前,似乎需要执行两个步骤。 (就像身份验证一样,显示器上会显示一个有关保管箱的框,因此您可以选择它并将其插入到该框中。但是全部都在一个保管箱中,但是我认为身份验证方面是隐藏的。我可以使用一个基本的保管箱索引,但是这让我感到难过。我不完全了解VBA> HTML方面的知识。

但是我的理解是,“ SchProgramID”是身份验证或过滤器代码,因此,一旦收到“ TrainerId”将打开,即可为您提供选定的名称,该名称会在您键入时过滤到一个框中,或者您可以使用从列表中选择鼠标。

我什至都无法集中精力。

有人可以帮我吗?

该站点的html代码如下:                     

                    <div class="form-group">
                        <label class="control-label col-md-2" for="TrainerId">Trainor</label>
                        <div class="col-md-8">


                            <select class="form-control chosen-select" data-live-search="true" data-val="true" data-val-number="The field Trainor must be a number." data-val-required="The Trainor field is required." id="TrainerId" name="TrainerId"><option value="">Select Trainor</option>
<option value="176">Undrico Divina Corpuz Jr.</option>
<option value="204">Domingo Bagadiong Go Jr.</option>
<option value="1200">Marnilo Sayson Sugano </option>
<option value="1238">Dexter Gaoiran Tomas </option>

我一直在玩的代码

'Dim fromSelect, fromSelect1 As HTMLSelectElement
'Dim evt, evt1 As Object
'Set evt = htmlDoc.createEvent("HTMLEvents")
'Set evt1 = htmlDoc.createEvent("HTMLEvents")
'evt.initEvent "change", True, False
'evt1.initEvent "change", True, False
'Set fromSelect = htmlDoc.getElementById("SchProgramId")
'OptionValue = "14526"
'If optionIndex >= 0 Then
'    fromSelect.selectedIndex = OptionValue
'    fromSelect.dispatchEvent evt
'Set fromSelect1 = htmlDoc.getElementById("TrainerId")
'OptionValue = "9570"
If optionIndex >= 0 Then
'    fromSelect.selectedIndex = OptionValue
'    fromSelect.dispatchEvent evt1
end if

1 个答案:

答案 0 :(得分:0)

目前尚不清楚SchProgramId的作用。

要显示下拉菜单,您应该可以使用:

ie.document.getElementById("TrainerId").Click

要在下拉列表中选择元素,您应该能够通过其值来定位value属性,例如1421用于第一位培训师(或按索引)

ie.document.querySelector("#TrainerId option[value='1421']").Selected = True

使用索引的示例:

ie.document.querySelector("#TrainerId").selectedIndex = 2