【发布时间】:2019-09-06 01:54:17
【问题描述】:
我正在为从网站下载信息制作代码。我的问题包括访问带有子菜单的下拉列表中的 Href。我尝试了很多代码,但其中任何一个都有效。
使用 getElementById 或 getElementsByClassName 的引用不起作用,因为此对象不支持函数 focus、click、selecteditems ="1"。下拉菜单的特殊性是首先通过单击进行管理,然后通过聚焦来管理它们。第一次单击三个点后,它会悬停一个名为“导出”的独特选项,接近它会悬停另外三个选项。我需要最后一个名为“下载相关扣除”。这是具体标签的代码。
<a title="Download associated deductions" class="ajax" href="exportPaymentLineItems.lvp?requestUID=&reportType=xls&reportName=Payments and associated deductions&ajax=true&isDrillable=" target="_blank">
<span class="prgx-icon excel-icon"></span> Download associated deductions
</a>
这是我在 VBA 中的代码
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
'...
IE.Document.getElementsByClassName("ajax").Click
之前在HTML代码中,第一次点击打开下拉菜单
<a class="btn btn-dots-vertical" id="dLabel" role="button" aria-expanded="true" href="#" data-toggle="dropdown" data-target="#">
</a>
<ul class="dropdown-menu multi-level dropdown-menu-right" role="menu" aria-labelledby="dropdownMenu">
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Export</a>
<ul class="dropdown-menu dropdown-menuright">
<li><a title="Excel" href="supplierReport.lvp?requestUID=&reportType=xls&reportName=BasicClaimsPaymentReport" target="_blank"><span class="prgx-icon excel-icon"></span>Excel</a></li>
<li><a title="CSV" href="supplierReport.lvp?requestUID=&reportType=csv&reportName=BasicClaimsPaymentReport" target="_blank"><span class="prgx-icon csv-icon"></span>CSV</a></li>
<li><a title="PDF" href="supplierReport.lvp?requestUID=&reportType=pdf&reportName=BasicClaimsPaymentReport" target="_blank"><span class="prgx-icon pdf-icon"></span>PDF</a></li>
'The one I need to click, download or copy to open in another explorer tab
<li>
<a title="Download associated deductions" class="ajax" href="exportPaymentLineItems.lvp?requestUID=&reportType=xls&reportName=Payments and associated deductions&ajax=true&isDrillable=" target="_blank">
<span class="prgx-icon excel-icon"></span> Download associated deductions
</a>
</li>
</ul>
</li>
</ul>
为了下载文档,我希望单击正确的类,复制 Href 并粘贴到新的资源管理器选项卡中,或者只是使用查询扇区启动下载。
【问题讨论】:
标签: html vba web-scraping drop-down-menu