我正在寻找一种从网站下拉框中提取数据的方法,特别是第二个选项组“所有基金公司”。
HTML代码的提取我正在抓取
</div><div class="large-5 medium-5 columns spacer-bottom padding-left-none"><div class="select_wrap"><select id="search-company" name="companyid" class="default">
<option value="">Search by company</option>
<optgroup label="Popular companies">
<option value="4">Hargreaves Lansdown</option>
<option value="1908">Lindsell Train</option>
<option value="55">Jupiter</option>
<option value="191">Legal & General</option>
</optgroup>
<optgroup label="All fund companies">
<option value="218">Aberdeen</option>
<option value="1080">Aberforth Unit Trust Managers</option>
<option value="141">Allianz Global Investors</option>
<option value="3472">Alquity Investment Management Limited</option>
<option value="1324">Amati Global Investors Ltd</option>
VBA:
Set htmlObj = html.getElementById("search-company")
For Each Child In htmlObj.getElementByClassName("optgroup")(1).Children
sqlId = Child.Value
sqlCompany = Child.innerText
Debug.Print (sqlId & " - " & sqlCompany)
Next
答案 0 :(得分:0)
谢谢Jeeped ......
这是设法解决问题的代码......不确定它是否是最有效的方法,但它有效:)
Set htmlObj = html.getElementById("search-company")
For Each Child In htmlObj.Children
If Child.Label = "All fund companies" Then Set htmlObj2 = Child
Next
For Each Child In htmlObj2.Children
sqlId = Child.Value
sqlCompany = Child.innerText
Debug.Print (sqlId & " - " & sqlCompany)
Next