Tej*_*jas 3 excel vba excel-vba
我需要使用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
Run Code Online (Sandbox Code Playgroud)
它给我的文字如下:
4723 N 63rd Dr 63,50008/17/201241.752,0747,6751972 $ 360.11
对于我无法分析并存储到Excel的不同单元格中的每个产品.
那么有没有办法以可管理的方式获取页面数据.如果我需要遍历一个循环,我很好.此外,我可以执行其他处理以将行数据正确填充到Excel中.
SWa*_*SWa 11
我使用下面的,因为我发现查询表缓慢,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
Run Code Online (Sandbox Code Playgroud)
我使用以下代码完成了它:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
69201 次 |
最近记录: |