如何使用vba从Datastore.prime中刮取数据

我试图从这个网站刮取数据http://www.whoscored.com/regions/252/tournaments/2/england-premier-league

当我使用检查元素时,我看到数据是表格格式,如下图所示。

在这里输入图像说明

源代码具有这种格式的数据。

在这里输入图像说明

DataStore.prime('stagefixtures',$ .extend({stageId:12496,isAggregate:false},calendar.parameter()),[[959688,1'2015年12月21日星期一','20:00',13 ,'阿森纳',0,167,'曼城',0,'2:1','2:0',1,1,'FT','1',0,1,112,0],[959683,4, '12月26日星期六','12:45',96,'斯托克',0,32,'曼联',0,'vs',, 0,1 ,,' – 1',0,1, 13,0],[959615,4'2015年12月26日星期六','15:00',24,'Aston Villa',0,29,'西汉姆',0,'vs',, 0,1 ''1',0,1,6,0],[959625,4,'2015年12月26日星期六','15:00',183,'伯恩茅斯',0,162,'水晶宫',0, 'vs',, 0,1 ,,' – 1',0,1,10,0],[959635,4,'2015年12月26日星期六','15:00',15,'Chelsea',0 ,27,'Watford',0,'vs',, 0,1 ,,' – 1',0,1,15,0],[959645,4'2015年12月26日星期六','15:00 ',26,'利物浦',0,14,'莱斯特',0,'vs',, 0,1 ,,' – 1',0,1,15,0],[959655,4' 2015年12月26日','15:00',167,'曼城',0,16,'桑德兰',0,'vs',, 0,1 ,,' – 1',0,1,4,0 ],[959691,4,'2015年12月26日星期六','15:00',259,'Swansea',0,175,'West Bromwich Albion',0,'vs',, 0,1 ,,' – 1 ',0,1,5,0],[959698,4',星期六,12月26日 2015'','15:00',30,'Tottenham',0,168,'Norwich',0,'vs',, 0,1 ,,' – 1',0,1,8,0],[959665, 4,'2015年12月26日星期六','17:30',23,'纽卡斯尔联',0,31,'埃弗顿',0,'vs',, 0,1 ,,' – 1',0, 1,7,0],[959674,4,'2015年12月26日星期六','19:45',18,'南安普敦',0,13,'阿森纳',0,'vs',, 0,1 ,,' – 1',0,1,11,0]]);

这段代码应该是从表格格式中删除数据,但在这种情况下我不知道该怎么做。

Option Explicit Sub WeeklyFixtures() Dim IE As Object, obj As Object Dim r As Integer, c As Integer, t As Integer Dim elemCollection As Object Set IE = CreateObject("InternetExplorer.Application") With IE .Visible = True .navigate ("http://www.whoscored.com/regions/252/tournaments/2/england-premier-league") While IE.ReadyState <> 4 DoEvents Wend Do While IE.busy: DoEvents: Loop ThisWorkbook.Sheet1.Clear Set elemCollection = IE.Document.getElementsByTagName("TABLE") For t = 0 To (elemCollection.Length - 1) For r = 0 To (elemCollection(t).Rows.Length - 1) For c = 0 To (elemCollection(t).Rows(r).Cells.Length - 1) ThisWorkbook.Worksheets(1).Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText Next c Next r Next t End With Set IE = Nothing End Sub 

试试这个代码:

 Option Explicit Sub GetWhoscoredData() Dim strCont, arrRows, strComma, arrQuots, i, arrCols With CreateObject("Microsoft.XMLHTTP") .Open "GET", "http://www.whoscored.com/regions/252/tournaments/2/england-premier-league", False .Send strCont = .ResponseText End With strCont = Split(strCont, "'stagefixtures'")(1) strCont = Split(strCont, "[[")(1) strCont = Split(strCont, "]);")(0) strCont = Replace(strCont, vbCrLf, "") strComma = Mid(CreateObject("Scriptlet.TypeLib").GUID, 2, 36) arrQuots = Split(strCont, "'") For i = 1 To UBound(arrQuots) Step 2 arrQuots(i) = Replace(arrQuots(i), ",", strComma) Next strCont = Join(arrQuots, "") arrRows = Split(strCont, "],[") For i = 0 To UBound(arrRows) arrCols = Split(arrRows(i), ",") Cells(i + 1, 1).Value = Replace(arrCols(2), strComma, ",") Cells(i + 1, 2).Value = Replace(arrCols(3), strComma, ",") Cells(i + 1, 3).Value = Replace(arrCols(14), strComma, ",") Cells(i + 1, 4).Value = Replace(arrCols(5), strComma, ",") Cells(i + 1, 5).NumberFormat = "@" Cells(i + 1, 5).Value = Replace(arrCols(10), strComma, ",") Cells(i + 1, 6).Value = Replace(arrCols(8), strComma, ",") Next Cells.Columns.AutoFit End Sub 

它给我的输出如下:

产量

你有Excel 2016吗? 在那里你应该能够得到它: Data – > New Query – > From Other Sources – > From Web 。 在那里你可以input你的url。 如果你logging所有你甚至得到相应的VBA代码。

在这里输入图像描述