我正在尝试从以下网站提取有关 NFL 新兵的数据:
http://espn.go.com/college-sports/football/recruiting/rankings/_/class/2013
我需要访问每个位置并将信息复制粘贴/提取到 Excel 电子表格中。正如您在下面看到的,每个位置的 URL 的唯一区别是大写的 VARIABLE。我需要这个变量来从运动员转变为角卫再到外接手。
http://espn.go.com/college-sports/football/recruiting/playerrankings/_/position/VARIABLE/class/2013/view/position
这是我正在使用的代码:
Dim array_example(18) As String
Sub Macro1()
array_example(0) = "athlete"
array_example(1) = "cornerback"
array_example(2) = "defensive-end"
array_example(3) = "defensive-tackle"
array_example(4) = "fullback"
array_example(5) = "inside-linebacker"
array_example(6) = "kicker"
array_example(7) = "offensive-center"
array_example(8) = "offensive-guard"
array_example(9) = "outside-linebacker"
array_example(10) = "offensive-tackle"
array_example(11) = "quarterback-dual-threat"
array_example(12) = "quarterback-pocket-passer"
array_example(13) = "running-back"
array_example(14) = "safety"
array_example(15) = "tight-end-h"
array_example(16) = "tight-end-y"
array_example(17) = "wide-receiver"
For i = 0 To 17
LastUsedRow = ActiveSheet.Range("A1").Offset(Sheet1.Rows.Count - 1, 0).End(xlUp).Row
LastEmptyRow = LastUsedRow + 1
Cell = "A" & LastEmptyRow
With ActiveSheet.QueryTables.Add(Connection:="URL;http://espn.go.com/college-sports/football/recruiting/playerrankings/_/position/" & array_example(i) & "/class/2013/view/position" & "", Destination:=Range("" & Cell & ""))
.Name = "s"
.FieldNames = True
.RowNumbers = True
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertEntireCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=True
End With
Next i
End Sub
我的问题是,每次我运行这段代码时,excel 都会卡住(有一个小圆盘会一直为光标旋转)。当我按 Escape 停止代码时,我发现只有一个位置已复制到 Excel 电子表格中。你能看看我的代码,让我知道我可以改变什么来循环遍历所有位置并将所有信息(一个接一个)复制到电子表格中吗?
万分感谢。