提问人:Sergio 提问时间:10/24/2023 最后编辑:BigBenSergio 更新时间:10/24/2023 访问量:39
如何使用 Microsoft EDGE 计算网页中的表数
How to count the number of tables in a webpage using Microsoft EDGE
问:
我在 Excel 数据查询方面苦苦挣扎。我需要从网页导入特定表。 所述表始终是页面中包含的表中的倒数第二个。 现在的挑战是,根据实际的网页,表的总数可能会发生变化。
所以我想检索表的数量并得到最后一个 - 1。到目前为止没有成功......
我试过这个(通过谷歌搜索找到)但没有成功:
Sub Count_Tables_on_a_Webpage()
Dim Edge As Object
Set Edge = CreateObject("Shell.Application")
Edge.ShellExecute "microsoft-edge:https://https://www.fidal.it/atleta/Elia-Ghezzi/fbORkpOicWo%3D"
Dim StartTime As Double
StartTime = Timer
Do While Edge.Windows.Count = 0 And Timer - StartTime < 10
' Wait for Edge to open or until 10 seconds have passed
Loop
If Edge.Windows.Count > 0 Then
Dim Doc As Object
Set Doc = Edge.Windows(Edge.Windows.Count - 1).Document
Dim TBLs As Object
Set TBLs = Doc.getElementsByTagName("Table")
MsgBox TBLs.Length
Else
MsgBox "Edge did not open within 10 seconds."
End If
End Sub
指令失败...Set TBLs = Doc.getElementsByTagName("Table")
如果我能获得这样的数字,那么我就可以创建一个自动例程来生成具有正确数据查询的工作表,在Excel中导入所需的表格(并且仅导入它)
有什么建议吗? 非常感谢
答: 暂无答案
评论