0
我對如何從這個網頁刮數據的問題:VBA動態網頁湊的Excel
它出現在IFRAME舉行和一堆JavaScript編程的出現在屏幕上。
當我嘗試收集在iframe下存放的span或div或tr標籤中的元素時,我似乎無法收集其中的數據。
我的目標是在class =「pane-legend-item-value pane-legend-line main」的元素內部保存的innertext。
顯然光標所在的那個特定的時間在屏幕上的innerText會因改變。所以我試圖做的是設置一個IE瀏覽器,它已經加載了頁面,光標放在正確的位置,在圖表的最後(爲了給我最後一個數據點),然後你可以將光標移出屏幕,然後我寫了一些簡單的代碼來抓取該IE窗口,然後嘗試了GetElements,但此時我無法獲取任何數據。
這是到目前爲止我的代碼,它非常粗略的,因爲我一直在試圖編輯,因爲我讀更多的選擇,但還沒有任何勝:(...任何想法或幫助將不勝感激!(截屏也是在底部)
Sub InvestingCom()
Dim IE As InternetExplorer
Dim htmldoc As MSHTML.IHTMLDocument 'Document object
Dim eleColth As MSHTML.IHTMLElementCollection 'Element collection for th tags
Dim eleColtr As MSHTML.IHTMLElementCollection 'Element collection for tr tags
Dim eleColtd As MSHTML.IHTMLElementCollection 'Element collection for td tags
Dim eleRow As MSHTML.IHTMLElement 'Row elements
Dim eleCol As MSHTML.IHTMLElement 'Column elements
Dim elehr As MSHTML.IHTMLElement 'Header Element
Dim iframeDoc As MSHTML.HTMLDocument
Dim frame As HTMLIFrame
Dim ieURL As String 'URL
'Take Control of Open IE
marker = 0
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next
my_url = objShell.Windows(x).document.Location
my_title = objShell.Windows(x).document.Title
If my_title Like "*" & "*" Then 'compare to find if the desired web page is already open
Set IE = objShell.Windows(x)
marker = 1
Exit For
Else
End If
Next
'Extract data
Set htmldoc = IE.document 'Document webpage
' I have tried span, tr, td etc tags and various other options
' I have never actually tried collecting an HTMLFrame but googled it however was unsuccessful
End Sub