3

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 Dr $ 63,50008 / 17 / 201241.752,0747,6751972 $ 360.11

分析してExcelのさまざまなセルに保存できない製品ごとに。

それで、私が管理可能な方法でページデータをフェッチすることができる方法があります。このためにループをトラバースする必要がある場合は問題ありません。また、行データをExcelに正しく入力するために追加の処理を行うこともできます。

4

2 に答える 2

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
于 2012-10-22T08:36:39.393 に答える
5

私は次のコードを使用してそれを行いました:

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
于 2012-10-20T15:45:39.497 に答える