只从网站获取特定的表格到Excel中

我需要使用VBA将http://www.zillow.com/homes/comps/67083361_zpid/中的表格导入到Excel中。 我只想要桌子,没有别的。 但是当我使用:

Set objIE = CreateObject("InternetExplorer.Application") With objIE .Visible = True .Navigate "http://www.zillow.com/homes/comps/67083361_zpid/" Do While .ReadyState <> 4: DoEvents: Loop Debug.Print .document.Body.outerText End With 

它给了我像文字:

4723 N 63rd $ 63,50008 / 17 / 201241.752,0747,6751972 $ 360.11

对于我无法分析和存储到Excel的不同单元中的每个产品。

那么有没有办法以可pipe理的方式获取页面数据? 我很好,如果我需要遍历这个循环。 此外,我可以做额外的处理,以正确填充行数据到Excel中。

我会使用下面,因为我发现查询表缓慢和IE极其缓慢;)

 Sub GetData() Dim x As Long, y As Long Dim htm As Object Set htm = CreateObject("htmlFile") With CreateObject("msxml2.xmlhttp") .Open "GET", "http://www.zillow.com/homes/comps/67083361_zpid/", False .send htm.body.innerhtml = .responsetext End With With htm.getelementbyid("comps-results") For x = 0 To .Rows.Length - 1 For y = 0 To .Rows(x).Cells.Length - 1 Sheets(1).Cells(x + 1, y + 1).Value = .Rows(x).Cells(y).innertext Next y Next x End With End Sub 

我用下面的代码做了它:

 Sub FetchData() With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://www.zillow.com/homes/comps/67083361_zpid", Destination:=Range( _ "$A$1")) .Name = "67083361_zpid" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlEntirePage .WebFormatting = xlWebFormattingNone .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End Sub