![](/img/trans.png)
[英]How do i extract specific data (name, details )from the website into excel with excel vba?
[英]excel vba extract data from website table
我正在嘗試抓取網站並且只需要 1 個值。 如何使用下面的代碼檢索購買方法? 見下面的html
Private Sub CommandButton1_Click()
Dim IE As Object
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = False
' URL to get data from
IE.Navigate Cells(1, 1)
' Statusbar
Application.StatusBar = "Loading, Please wait..."
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 5, Now)
Loop
Application.StatusBar = "Searching for value. Please wait..."
Dim tr As Object, td As Object, tb As Object
Dim value As String
Set tb = IE.Document.getElementById("prop_desc clearfix")
For Each tr In tb.Rows 'loop through the <tr> rows of your table
For Each td In tr.Cells 'loop through the <th> cells of your row
value = td.outerText 'your value is now in the variable "value"
MsgBox value
Next td
Next tr
' Show IE
IE.Visible = True
' Clean up
Set IE = Nothing
Application.StatusBar = ""
End Sub
</div> </div> <div class="prop_desc clearfix"><div class = "span-half"> <h3>RV Park/Campground for Sale</h3> <table> <tr> <td>Number of RV Lots: </td> <td>270</td> </tr> <tr> <td>Size:</td> <td> 157 acre(s) </td> </tr> <tr> <td>Purchase Method:</td> <td>Cash, New Loan</td> </tr> <tr> <td>Status:</td> <td> Active </td> </tr> <tr> <td>Property ID:</td> <td>966994</td> </tr> <tr> <td>Posted on:</td> <td>Jul 10, 2018</td> </tr> <tr> <td>Updated on:</td> <td>Jul 10, 2018</td> </tr> <tr>
您可以按類按索引定位,然后按索引定位 td
Option Explicit
Public Sub GetInfo()
Dim IE As New InternetExplorer
With IE
.Visible = True
.navigate "https://www.rvparkstore.com/rv-parks/902077--2843-lake-frontage-42-acres-for-sale-in-north-central-us"
While .Busy Or .readyState < 4: DoEvents: Wend
Debug.Print .document.getElementsByClassName("span-half")(0).getElementsByTagName("td")(5).innerText
.Quit '<== Remember to quit application
End With
End Sub
更新:
HTML 在這里https://docs.google.com/document/d/1J5tDV99IbzucCB_z8QX8lDa4X3ecxQbQOWeVy5B7Irg/edit?usp=sharing
請使用鏈接獲取更多信息 jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.