我写了一个爬虫来解析来自洪流网站的电影信息。我用IE
和queryselector
。
我的代码确实解析了所有内容。当一切完成后,它会抛出错误而不是退出浏览器。如果我取消错误框,那么我可以看到结果。
这是完整的代码:
Sub Torrent_Data()
Dim IE As New InternetExplorer, html As HTMLDocument
Dim post As Object
With IE
.Visible = False
.navigate "https://yts.am/browse-movies"
Do While .readyState <> READYSTATE_COMPLETE: Loop
Set html = .Document
End With
For Each post In html.querySelectorAll(".browse-movie-bottom")
Row = Row + 1: Cells(Row, 1) = post.queryselector(".browse-movie-title").innerText
Cells(Row, 2) = post.queryselector(".browse-movie-year").innerText
Next post
IE.Quit
End Sub
我上传了两张图片来显示错误。
两个错误同时出现。
我正在使用 Internet Explorer 11。
如果我像下面这样尝试,它会成功地带来结果而没有问题。
Sub Torrent_Data()
Dim IE As New InternetExplorer, html As HTMLDocument
Dim post As Object
With IE
.Visible = False
.navigate "https://yts.am/browse-movies"
Do While .readyState <> READYSTATE_COMPLETE: Loop
Set html = .Document
End With
For Each post In html.getElementsByClassName("browse-movie-bottom")
Row = Row + 1: Cells(Row, 1) = post.queryselector(".browse-movie-title").innerText
Cells(Row, 2) = post.queryselector(".browse-movie-year").innerText
Next post
IE.Quit
End Sub
添加到库的参考:
- 微软互联网控制
- Microsoft HTML 对象库
是否有任何参考可以添加到库中以消除错误?