我成功编写了 VBA 从网页中抓取数据。
由于数据会定期更新,我希望它也能在我的 Excel 文档中更新。
我得到的数据是列出的所有博彩公司的不同赔率。
我为变量 HTMLRow 尝试了 .refreshperiod .refresh 函数,但由于某种原因它不起作用
Sub Scrape()
For x = 1 To 5
Worksheets("links").Select
Worksheets("links").Activate
mystr = "https://easyodds.com/tennis/challenger/santiago-chile/928271/match-result"
mystr = Cells(x, 1)
Dim XMLPage As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim HTMLOdds As MSHTML.IHTMLElement
Dim HTMLRow As Object
Dim HTMLCell As MSHTML.IHTMLElement
Dim RowNum As Long, ColNum As Integer
XMLPage.Open "GET", mystr, False
XMLPage.send
Dim XMLResp As MSHTML.IHTMLElement
HTMLDoc.body.innerHTML = XMLPage.responseText
Set HTMLOdds = HTMLDoc.getElementById("betsTable")
Worksheets.Add
Cells.Select
Selection.NumberFormat = "0.00"
Range("A1").Value = mystr
RowNum =
Set HTMLRow = HTMLOdds.getElementsByTagName("tbody")
For Each HTMLRow In HTMLOdds.getElementsByTagName("tr")
ColNum = 1
For Each HTMLCell In HTMLRow.getElementsByTagName("Div")
Cells(RowNum, ColNum) = HTMLCell.innerText
ColNum = ColNum + 1
Next HTMLCell
RowNum = RowNum + 1
Next HTMLRow
Next x
End Sub