Span ID值未使用excel VBA抓取

时间:2019-03-29 18:20:09

标签: excel vba web-scraping

我有Excel代码,可从nowgoal.com抓取匹配结果,该文件最近停止工作,尽管nowgoal页面结构未更改

单元格AF2包含“ 1”,指示应控制应刮擦哪些行的数据(基本上,应在刮擦中处理在A列中添加了编号1的每一行)。

每行都包含nowgoal ID(http://www.nowgoal.com/analysis/1401651.html-ID为1401651),应分别将主球目标刮至C列,将离场目标刮至D列)

这是我的代码:

Option Explicit
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal Milliseconds As LongPtr)
Sub GetResult()

Const START_ROW As Integer = 3
Const START_COL As Integer = 3

Const ANALYSIS_PAGE As String = "http://www.nowgoal.com/analysis/"

Dim LString As String, LArray() As String

'get week number
Dim week As Integer: week = ActiveSheet.Cells(2, 32)

'instantiate worksheet to process
Dim wks As Worksheet: Set wks = ActiveSheet

'instantiate browser
Dim ie As New InternetExplorer
ie.Visible = True

'instantiate variables
Dim url As String, i As Integer, j As Integer
Dim nowGoalID As Long, iRow As Long, lastRow As Long

With wks

    lastRow = .Cells(Rows.Count, 1).End(xlUp).Row

    For iRow = START_ROW To lastRow

        'check week
        If .Cells(iRow, 1) <> week Or .Cells(iRow, 2) = "" Then GoTo nextRow
        Application.Goto .Cells(iRow, 1), True
        DoEvents

        nowGoalID = .Cells(iRow, 2)
        Application.StatusBar = "Processing row: " & iRow & " " & nowGoalID

        url = ANALYSIS_PAGE & nowGoalID & ".html"

        ie.navigate url
        While ie.Busy: DoEvents: Sleep 100: Wend
        While ie.readyState <> READYSTATE_COMPLETE: DoEvents: Sleep 100: Wend

        LString = Mid(ie.document.getElementById("mScore").innerText, 8)
        LArray = Split(LString, "-")

        Cells(70, 2).Value = LArray

nextRow:
Next iRow
End With

ie.Quit
Set ie = Nothing
MsgBox "All done", vbInformation
End Sub

Macro打开IE并找到合适的网站,但未完成抓取

1 个答案:

答案 0 :(得分:1)

我认为您也许可以将ID连接到ajax xhr

Database: Global
Tables: Users and ClientUsers

Database: Client
Tables: Users