<input type="hidden" id="request" value='[]'>
<input type="hidden" id="baseUrl" value='index/index'>
<div class="m-pager" id="m-page">
<a class="cur" page="1" href="javascript:void(0)">1</a> <a class="changePage" page="2" href="javascript:void(0);">2</a> <a class="changePage" page="3" href="javascript:void(0);">3</a> <a class="changePage" page="4" href="javascript:void(0);">4</a> <a class="changePage" page="5" href="javascript:void(0);">5</a> <a class="changePage" page="2" href="javascript:void(0);">下一页</a><a class="changePage" page="256" href="javascript:void(0);">尾页</a><span class="page_info">1/256</span>
</div>
首先,确保已经安装了Microsoft Internet Controls引用。在VBA编辑器中,单击“工具”>“引用”并选中“Microsoft Internet Controls”。
然后,在代码模块中插入以下代码:
Option Explicit
Sub GetNextPageButton()
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim nextPageButton As HTMLAnchorElement
' 创建Internet Explorer实例
Set IE = New InternetExplorer
' 进入您要爬取的网页URL
IE.Navigate "http://your-website-url.com"
' 等待网页加载完成
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
' 获取网页的HTML内容
Set HTMLdoc = IE.Document
' 查找下一页按钮
Set nextPageButton = HTMLdoc.querySelector("a.changePage[page='2']")
' 输出下一页按钮的文本
If Not nextPageButton Is Nothing Then
MsgBox "下一页按钮: " & nextPageButton.innerText
Else
MsgBox "下一页按钮未找到"
End If
' 关闭Internet Explorer实例
IE.Quit
Set IE = Nothing
End Sub
修改代码中的网页URL,将其替换为您要爬取的实际网址。
运行代码,它将获取下一页按钮并显示一个消息框,包含按钮的文本。
注意:由于VBA中的Internet Explorer已经过时,且在某些情况下可能无法正常工作,因此您可能会考虑使用更现代的Web爬虫技术,例如Python的BeautifulSoup或Selenium库。追问
感谢解答,已经解决V5。