gpt4 book ai didi

excel - 如何使用 "pagination"单击网络中的某个页面?

转载 作者:行者123 更新时间:2023-12-03 02:18:55 25 4
gpt4 key购买 nike

我有一个程序可以打开一个网页并计算其中有多少页。然后我需要点击某个页面,例如第3页。有人知道该怎么做吗?我在下面详细介绍了宏的代码。非常感谢!

Sub test()

Dim element As IHTMLElement
Dim elements As IHTMLElementCollection
Dim ie As InternetExplorer
Dim numberOfPages As Double
Dim html As HTMLDocument

Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://cebra.com.ar/category/73/Juego-de-Construccion.html"
Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Loading Web page …"
DoEvents
Loop
Set html = ie.document
Set elements = html.getElementsByClassName("container")
Set ElementCol = html.getElementsByTagName("a")
numberOfPages = ie.document.querySelectorAll(".setPage").Length
'Here I want to click on a certain page, for example, number 3
For Each ele In ie.document.getElementsByTagName("li")
For Each element In elements
If element.className = "container" Then
'Do something
End If
Next element
Next
MsgBox "Done"

End Sub

最佳答案

尝试下面的代码

Option Explicit

Sub test()

Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim element As IHTMLElement

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "https://cebra.com.ar/category/73/Juego-de-Construccion.html"
WaitIE ie
Set html = ie.Document
Set element = html.querySelector("a.setPage")
element.setAttribute "data-value", "3" ' set the page number you want open
element.click
WaitIE ie

MsgBox "Done"

End Sub

Sub WaitIE(ie As InternetExplorer)

Application.StatusBar = "Loading Web page …"
Do While ie.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Application.StatusBar = "Ready"

End Sub

关于excel - 如何使用 "pagination"单击网络中的某个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56437028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com