testing - VBA 抓取 div 元素
问题描述
这只是一个测试,请忽略到目前为止你所看到的一切。
解决方案
你可以使用 xmlhttp,而不是浏览器,然后下面的循环写出所有的 div 信息。在如何仅获取感兴趣的数据时,我可能会更有选择性,但我希望以下内容符合您所要求的精神。
Option Explicit
Public Sub GetInfo()
Dim data As Object, i As Long, html As HTMLDocument, r As Long, c As Long, item As Object, div As Object
Set html = New HTMLDocument '<== VBE > Tools > References > Microsoft HTML Object Library
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "https://www.worten.pt/grandes-eletrodomesticos/maquinas-de-roupa/maquinas-de-roupa-ver-todos-marca-BALAY-e-BOSCH-e-SIEMENS?per_page=100", False
.send
html.body.innerHTML = .responseText
End With
Set data = html.getElementsByClassName("w-product__content")
For Each item In data
r = r + 1: c = 1
For Each div In item.getElementsByTagName("div")
With ThisWorkbook.Worksheets("Sheet1")
.Cells(r, c) = div.innerText
End With
c = c + 1
Next
Next
End Sub
推荐阅读
- java - Spring Boot Security PermitAll with RequestHeaderMatcher not working
- sql - 找不到函数 Postgres
- node.js - 柴 nodejs 和 mongodb
- java - 六边形架构的Java代码示例?
- heroku - 错误:不能运行超过 1 个免费大小的测功机
- java - 如何在 Elasticsearch 中使用 RestHighLevelClient 获取不同的值?
- swift - removeAllPendingNotificationRequests() 是否会永久取消本地时间通知?
- javascript - How to dynamically add function objects to an object function map
- python - 'unicodeescape' 编解码器无法解码字节:截断 \xXX 转义 Mac OS
- keras - Keras 中的形状与 CNN 不兼容