excel - 从网站查询选择器中提取链接全部
问题描述
我已使用以下 vba 代码从中提取网站链接
进入excel电子表格。但这里似乎有一些问题,我的电子表格中没有显示任何内容。感谢是否有人可以在这里指出我的错误。
以下是我希望将其提取到 Excel 电子表格中的网站链接列表。
Sub ScrapLink()
Dim p As Integer
Application.ScreenUpdating = False
p = InputBox("Please insert page number")
Application.ScreenUpdating = False
On Error GoTo ErrorHandler:
Worksheets("results").Cells(1, 1).Value = Worksheets("sheet1").Cells(1, 1).Value
For u = 2 To p
Worksheets("results").Cells(u, 1).Value = Worksheets("sheet1").Cells(1, 1).Value & "&page=" & u
Application.DisplayAlerts = False
Application.DisplayAlerts = True
ErrorHandler:
Application.ScreenUpdating = True
Next u
Dim IE As New InternetExplorer, html As HTMLDocument
Dim x As Long
Application.ScreenUpdating = False
x = WorksheetFunction.CountA(Worksheets("results").Range("A1:A1000"))
With IE
For u = 1 To x
IE.Visible = True
IE.Navigate Worksheets("results").Cells(u, 1).Value
While .Busy Or .ReadyState < 4: DoEvents: Wend
Application.Wait Now + TimeSerial(0, 0, 1)
Application.StatusBar = "Trying to go to website"
DoEvents
Dim links As Object, i As Long
Set links = .Document.querySelectorAll("#bm_ajax_container
[href^='/market_information/announcements/company_announcement/']")
For i = 1 To links.Length
With ThisWorkbook.Worksheets("Sheet1")
Range("A" & rows.count).End(xlUp).Offset(1).Value = links.item(i - 1)
End With
Next i
Next u
.Quit
End With
Worksheets("results").Range("a1:a1000").Clear
End Sub
解决方案
尝试
For i = 0 To links.Length -1
和
Range("A" & rows.count).End(xlUp).Offset(1).Value = links.item(i ).href
假设选择器正确。nodeLists 基于 0。
推荐阅读
- database - 在 MongoDB 中,您可以将来自不同集合的两个索引组合在一起吗?
- java - Java DefaultTreeModel 的 removeNodeFromParent 正在删除不正确的节点
- routes - 如何检查用于调用页面/组件的路由?
- flutter - 地理定位器包不起作用,颤振
- typescript - NestJS 使用 .env 和 @nestjs/config 设置 TypeOrm 连接
- react-native - 如何在 React Native 中使用 Firebase 实现 Microsoft 登录?
- java - 使用 com.sun.tools 附加到当前 VM
- android - Tasks.await(task) 显示不适当的阻塞方法调用警告
- php - 导入用分号分隔并用引号分隔的 CSV
- html - HTML5 输入的“min”属性不会使日历的过去日期变灰