我想要声明一个节点数组(这不是问题),然后在数组的每个元素内部刮两个子节点的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