我试图从本网站http://www.whoscored.com/regions/252/tournaments/2/england-premier-league如何从Datastore.prime使用VBA
抽取数据当我使用检查元素我看到的数据以表格形式如上图下方抽取数据。
的源代码在这个格式的数据。
DataStore.prime( 'stagefixtures',$ .extend({级ID:12496,isAggregate:假},calendar.parameter()),〔959688,1,“周一,十二月'2015','20:00',13,'Arsenal',0,167,'曼城',0,'2:1','2:0',1,1,'FT','1',0 ,1,112,0] ,[959683,4,'2015年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'West Ham',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,'沃特福德',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',Saturday ,'2015年12月26日','15:00',30'托特纳姆',0,168'诺维奇',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
你想使用VBA来检索数据,为什么呢?一个简单的'网络查询'工作在我的电脑上就好了。只需点击“数据”菜单上的“获取外部数据”并选择“从网站”。在那里你可以输入你给我们的URL并选择你想要检索的表格。你甚至可以设置查询来刷新每个'xx'秒。 – Ralph
@Ralph我在表格 – Anuj
附近找不到'next - >'符号当我尝试在IE 11中打开网站时,它并未完成加载,表格为空。在Firefox中,它工作正常。该网站在IE中适合你吗?在使用Firefox的屏幕截图中,您是否尝试手动打开IE中的页面? – dee