我的程序通过<a>
从网站收集getElementsByTag("a")
个标签。在从中提取的网站上,每个<a>
标签都有一个href链接。通过访问VBA如何进入该href网站?
这是我到目前为止所拥有的
Dim ie As InternetExplorer
Dim HTML As HTMLDocument
Dim b As IHTMLElement
Dim alist As IHTMLElementCollection
Set ie = New InternetExplorer
ie.Visible = False
ie.Navigate ("https://www.example.com")
Set HTML = ie.Document
Set ie = Nothing
Set alist = HTML.getElementsByTagName("a")
For Each b In alist
Set ie = New InternetExplorer
Next b
答案 0 :(得分:0)
只需调用href
属性即可获取链接:
For Each b In alist
Set ie = New InternetExplorer
ie.navigate b.href
'wait for IE to load
Do: Loop While ie.busy Or ie.readystate <> 4
Next b
你还需要在初始导航调用中添加``wait for IE to load`部分,否则代码将在IE完全加载之前继续执行。