我正在尝试从此网站抓取数据link
使用以下代码
Sub Scrape()
Dim objIE As InternetExplorer
Dim ele As Object
Dim y As Integer
Dim result As String
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "http://www.mca.gov.in/mcafoportal/viewPublicDocumentsFilter.do"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
objIE.document.getElementById("companyName").Value = "tata"
objIE.document.getElementById("companyChk").Click
objIE.document.getElementById("viewDocuments_0").Click
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
y = 1
For Each ele In objIE.document.getElementById("results").getElementsByTagName("tr") 'error displayed here
Debug.Print ele.textContent
Sheets("Sheet1").Range("A" & y).Value = ele.Children(0).textContent
'put text of 2nd 'td' in col B
Sheets("Sheet1").Range("B" & y).Value = ele.Children(1).textContent
'put text of 3rd 'td' in col C
Sheets("Sheet1").Range("C" & y).Value = ele.Children(2).textContent
'put text of 4th 'td' in col D
Sheets("Sheet1").Range("D" & y).Value = ele.Children(3).textContent
'increment row counter by 1
y = y + 1
'repeat until last ele has been evaluated
Next
End Sub
当我逐行运行时,它可以正常运行,但在完全运行时会显示
错误'424':需要对象。
我不知道为什么会发生这种情况