【发布时间】:2017-11-19 16:37:35
【问题描述】:
不知道如何从代码中使用的页面获取所有公司链接。运行我的脚本,我只得到 20 个链接。该页面具有延迟加载方法,这就是为什么我无法获得所有这些方法。对此的任何意见将不胜感激。到目前为止,我已经尝试过:
Sub Company_links()
Const lnk = "http://fortune.com"
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim topic As Object
With http
.Open "GET", "http://fortune.com/fortune500/list/", False
.send
html.body.innerHTML = .responseText
End With
For Each topic In html.getElementsByClassName("small-12 column row")
x = x + 1
With topic.getElementsByTagName("a")
If .Length Then Cells(x, 1) = lnk & Split(.item(0).href, "about:")(1)
End With
Next topic
Set html = Nothing: Set topics = Nothing
End Sub
【问题讨论】:
-
如果站点使用 ajax 加载剩余的链接。您需要先让页面加载那些剩余的链接。
标签: vba web-scraping web-crawler