我在VBA代码中打开了一个新链接,但它只在新窗口中打开,因此代码不会跟随到新窗口。
我被难住了这是我的代码。
<div class="table-r">
<table class="table-c">
<tbody>
<tr class="bg">
<td class=" np"> <a title="comm" href="logcomm-e.asp?id=3" rel="history">3</a> </td>
<td class=" np"> <a title="comm" href="logcomm-e.asp?id=2" rel="history">2</a> </td>
<td class=" np"> <a title="comm" href="logcomm-e.asp?id=1" rel="history">1</a> </td>
</tr>
</tbody>
</table>
</div>Sub IEScrape()
Dim IE As Object
Set IE = New InternetExplorerMedium
With IE
.Visible = True
.Navigate "inhouse web site"
While IE.readyState <> 4
DoEvents
Wend
.document.querySelector("a[href*='logcomm-e.asp?id=']").Click
While IE.readyState <> 4
DoEvents
Wend
End With
Set IE = Nothing
ActiveWorkbook.Save
End Sub我希望当我运行get元素并将其打印到一个单元格时,它来自新的href链接。我不能直接转到链接,因为每天都有新的链接,href get也在更新。通过使用querySelector,它可以点击最新的条目。目前是3点,明天是4点,以此类推。
发布于 2019-06-14 15:18:57
使用class和type选择器(但+ to @vityata's)来获取href并导航到href会稍微快一点。QuerySelector返回第一个匹配项,该匹配项将是您案例中的最新匹配项
ie.Navigate2 .document.querySelector(".table-c a").hrefhttps://stackoverflow.com/questions/56585498
复制相似问题