1
<span itemprop="streetAddress">
**94 Grand St**
</span>
如何讓在Excel VBA中從網站獲取的數據
我已經試過的getElementById,getelementbyname等,但沒有通過getelementby方法這個數據正在
Option Explicit
Sub find()
'Uses late binding, or add reference to Microsoft HTML Object Library
' and change variable Types to use intellisense
Dim ie As Object 'InternetExplorer.Application
Dim html As Object 'HTMLDocument
Dim Listings As Object 'IHTMLElementCollection
Dim l As Object 'IHTMLElement
Dim r As Long
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = False
.Navigate "http://www.yelp.com/biz/if-boutique-new-york#query:boutique"
' Don't show window
'Wait until IE is done loading page
Do While .readyState <> 4
Application.StatusBar = "Downloading information, Please wait..."
DoEvents
Loop
Set html = .Document
End With
Set Listings = html.getElementsByTagName("span") ' ## returns the list
MsgBox (Listings(0))
For Each l In Listings
'## make sure this list item looks like the listings Div Class:
' then, build the string to put in your cell
Range("A1").Offset(r, 0).Value = l.innerText
r = r + 1
Next
Set html = Nothing
Set ie = Nothing
End Sub
上述程序所使用我得到span標記內的innerText值...但它不起作用
問題要求代碼必須表現出對問題的理解最小正在解決。包括嘗試解決方案,爲什麼他們沒有工作,以及預期的結果。另請參閱:[堆棧溢出問題清單](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist) –
它做什麼而不是工作?你的getElementsByTagName看起來不錯,那麼當你運行這個時會發生什麼? –
你有沒有調試過我們的代碼..哪裏出錯? –