我想要聲明一個節點數組(這不是問題),然後在數組的每個元素內部刮兩個子節點的innerHTML
- 以SE爲例使用對象方法IE
),假設我試圖在主頁上提取標題和問題摘要,則有一個節點數組(類名稱:「問題摘要」)。從使用VBA的站點刮掉innerHTML
有那麼兩個孩子節點(瓦 - 類名稱:「問題 - 超鏈接」和提取物 - 類名稱:「摘錄」)我正在使用的代碼是如下:
Sub Scraper()
Dim ie As Object
Dim doc As Object, oQuestionShells As Object, oQuestionTitle As Object, oQuestion As Object, oElement As Object
Dim QuestionShell As String, QuestionTitle As String, Question As String, sURL As String
Set ie = CreateObject("internetexplorer.application")
sURL = "https://stackoverflow.com/questions/tagged/excel-formula"
QuestionShell = "question-summary"
QuestionTitle = "question-hyperlink"
Question = "excerpt"
With ie
.Visible = False
.Navigate sURL
End With
Set doc = ie.Document 'Stepping through so doc is getting assigned (READY_STATE = 4)
Set oQuestionShells = doc.getElementsByClassName(QuestionShell)
For Each oElement In oQuestionShells
Set oQuestionTitle = oElement.getElementByClassName(QuestionTitle) 'Assigning this object causes an "Object doesn't support this property or method"
Set oQuestion = oElement.getElementByClassName(Question) 'Assigning this object causes an "Object doesn't support this property or method"
Debug.Print oQuestionTitle.innerHTML
Debug.Print oQuestion.innerHTML
Next
End Sub
我是個白癡!謝謝 :) – Jeremy