VBA提取从网页中选择下拉列表中的下拉列表

问题描述 投票:1回答:1

我正在尝试提取所选下拉项目的innertext。我要回来的是“机构2”

<select name="ctl00$ContentPlaceHolder1$ddlInstName" id="ctl00_ContentPlaceHolder1_ddlInstName" style="background-color: rgb(255, 255, 128);">
        <option value="Select…">Select…</option>
        <option value="1867">Institution 1</option>
        <option selected="selected" value="719">Institution 2</option>
        <option value="1971">Institution 3</option>

这就是我所拥有的,但它只返回0值

account = IE.document.getElementById("ctl00_ContentPlaceHolder1_ddlInstName").getElementsByTagName("selected")(0).innerText

任何帮助将不胜感激

html excel vba web-scraping extract
1个回答
1
投票

使用selected的属性选择器。它不是标签。

ie.document.querySelector("#ctl00_ContentPlaceHolder1_ddlInstName [selected]").innerText
© www.soinside.com 2019 - 2024. All rights reserved.