【发布时间】:2018-01-05 01:43:11
【问题描述】:
使用下面的脚本,我成功地将 HTML 表中的值从以下链接返回到工作簿中:link1 和 link2。但是当我尝试对以下link3 使用相同的脚本时,它不会返回任何内容。我认为这是由于网站上存在复杂的 HTML 表格结构。我相信由于表格的复杂性,代码需要调整 .Item(0) 数字,请指教。
Sub Web_Data()
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim topic As HTMLHtmlElement
With http
.Open "GET", "http://www.dolphinfitness.co.uk/en/optimum-nutrition/", False
.send
html.body.innerHTML = .responseText
End With
For Each topic In html.getElementsByClassName("category-products")
With topic.getElementsByClassName("product-name")
If .Length Then x = x + 1: Cells(x, 1) = .Item(0).innerText
End With
With topic.getElementsByClassName("price")
If .Length Then Cells(x, 2) = .Item(0).innerText
End With
Next topic
End Sub
【问题讨论】:
-
能否请您补一下脚本,我去下载selenium。
-
我需要安装哪个版本才能完成这项工作? selenium download page
-
顺便说一句,看到你脚本中的链接,我删除了我的评论。这是你需要抓取的链接吗?
-
This is the link that I want to scrape off. 但基本上我想建立一个包含所有三个网站的数据库,以便在一个地方查看价格。但是此评论中提到的链接该脚本不起作用。
-
您的脚本已准备就绪,我可以运行它,但您现在无法运行它。
标签: vba excel web-scraping html-table