gpt4 book ai didi

vba - 使用 VBA 列出网页的所有 URL 地址

转载 作者:行者123 更新时间:2023-12-04 20:58:37 25 4
gpt4 key购买 nike

我使用以下代码加载网站 http://www.flashscore.com/soccer/england/premier-league/results/ .

在我找到并单击“显示更多比赛”链接后,所有足球比赛都加载到浏览器中。

下面的代码将只给出匹配结果的前半部分,即在按下“显示更多匹配”链接之前显示的事件。

我的问题是如何列出所有事件的 URL 地址?

Sub Test_Flashscore()

Dim URL As String
Dim ie As New InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim dictObj As Object: Set dictObj = CreateObject("Scripting.Dictionary")
Dim tRowID As String

URL = "http://www.flashscore.com/soccer/england/premier-league/results/"

With ie
.navigate URL
.Visible = True
Do Until .readyState = READYSTATE_COMPLETE: DoEvents: Loop
Set HTMLdoc = .document
End With


For Each objLink In ie.document.getElementsByTagName("a")

If Left(objLink.innerText, 4) = "Show" Or Left(objLink.innerText, 4) = "Arat" Then

MsgBox "The link was founded!"
objLink.Click

Exit For

End If

Next objLink


With HTMLdoc

Set tblSet = .getElementById("fs-results")
Set mTbl = tblSet.getElementsByTagName("tbody")(0)
Set tRows = mTbl.getElementsByTagName("tr")
With dictObj
'If if value is not yet in dictionary, store it.
For Each tRow In tRows
'Remove the first four (4) characters.
tRowID = Mid(tRow.ID, 5)
If Not .Exists(tRowID) Then
.add tRowID, Empty
End If
Next tRow
End With
End With

i = 14
For Each Key In dictObj

ActiveSheet.Cells(i, 2) = "http://www.flashscore.com/" & Key & "/#match-summary"
i = i + 1

Next Key

Set ie = Nothing
MsgBox "Process Completed"

End Sub

最佳答案

您需要稍等片刻才能加载其余内容 - 单击链接会触发对服务器的 GET 请求,因此需要返回内容并且需要在页面上呈现内容,然后才能获取它。

关于vba - 使用 VBA 列出网页的所有 URL 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41556001/

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