无法使用 vba 填充来自网站的结果
Can't populate results from a website using vba
我在 vba 中创建了一个脚本,使用 IE 获取在 select 从下拉列表中选择一个选项时弹出的内容。在网站的登录页面中,有一个名为 Type
的下拉菜单。当我点击 Type
时,我在那里看到几个选项,我想点击其中的 corporate bond
。生成结果后,我想解析 WKN
.
我已尝试通过单击下拉菜单并从那里 select 选择一个选项来使用我当前的脚本来填充结果。但是,它单击下拉菜单和 select 所需的选项,但无法在 InternetExplorer 中产生任何结果。
如何填充和解析结果 select 从下拉列表中选择一个选项?
我目前的尝试:
Sub SelectItem()
Const link = "https://www.boerse-stuttgart.de/en/tools/product-search/bonds/"
Dim IE As New InternetExplorer, Html As HTMLDocument, post As Object, T As Date
With IE
.Visible = True
.navigate link
While .Busy Or .readyState < 4: DoEvents: Wend
Set Html = .document
End With
Application.Wait Now + TimeValue("00:00:15")
Html.querySelector("#bsg-filters-btn-bgs-filter-3 .bsg-btn__icon").Click
Application.Wait Now + TimeValue("00:00:05")
Html.querySelector("#bsg-filters-menu-bgs-filter-3 .bsg-scrollbox label[for='bsg-checkbox-3053']").Click
Application.Wait Now + TimeValue("00:00:05")
Html.querySelector(".bsg-dropdown__footer button[type='button']").Click
End Sub
您熟悉定时循环,因此可以为以下内容添加超时。我使用 css 选择器来定位元素。我监视旋转圆圈的消失,作为不同点的页面加载量度。最后,我监视是否存在结果项 nodeList 节点。
Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls
Public Sub GetCodes()
Dim ie As New InternetExplorer, btn As Object, items As Object, i As Long
With ie
.Visible = True
.Navigate2 "https://www.boerse-stuttgart.de/en/tools/product-search/bonds"
While .Busy Or .readyState < 4: DoEvents: Wend
Do
Loop Until .document.querySelectorAll(".bsg-loader-ring__item").Length = 0
.document.querySelector("#bsg-filters-btn-bgs-filter-3").Click
.document.querySelector("#bsg-checkbox-3053").Click
Set btn = .document.querySelector("#bsg-filters-menu-bgs-filter-3 .bsg-btn__label")
Do
Loop While btn.innerText = "Close"
btn.Click
Do
Loop Until .document.querySelectorAll(".bsg-loader-ring__item").Length = 0
Dim count As Long
Do
On Error Resume Next
Set items = .document.querySelectorAll(".bsg-table__tr td:first-child")
count = items.Length
On Error GoTo 0
Loop While count = 0
For i = 0 To items.Length - 1
Debug.Print items.item(i).innerText
Next
.Quit
End With
End Sub
我在 vba 中创建了一个脚本,使用 IE 获取在 select 从下拉列表中选择一个选项时弹出的内容。在网站的登录页面中,有一个名为 Type
的下拉菜单。当我点击 Type
时,我在那里看到几个选项,我想点击其中的 corporate bond
。生成结果后,我想解析 WKN
.
我已尝试通过单击下拉菜单并从那里 select 选择一个选项来使用我当前的脚本来填充结果。但是,它单击下拉菜单和 select 所需的选项,但无法在 InternetExplorer 中产生任何结果。
如何填充和解析结果 select 从下拉列表中选择一个选项?
我目前的尝试:
Sub SelectItem()
Const link = "https://www.boerse-stuttgart.de/en/tools/product-search/bonds/"
Dim IE As New InternetExplorer, Html As HTMLDocument, post As Object, T As Date
With IE
.Visible = True
.navigate link
While .Busy Or .readyState < 4: DoEvents: Wend
Set Html = .document
End With
Application.Wait Now + TimeValue("00:00:15")
Html.querySelector("#bsg-filters-btn-bgs-filter-3 .bsg-btn__icon").Click
Application.Wait Now + TimeValue("00:00:05")
Html.querySelector("#bsg-filters-menu-bgs-filter-3 .bsg-scrollbox label[for='bsg-checkbox-3053']").Click
Application.Wait Now + TimeValue("00:00:05")
Html.querySelector(".bsg-dropdown__footer button[type='button']").Click
End Sub
您熟悉定时循环,因此可以为以下内容添加超时。我使用 css 选择器来定位元素。我监视旋转圆圈的消失,作为不同点的页面加载量度。最后,我监视是否存在结果项 nodeList 节点。
Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls
Public Sub GetCodes()
Dim ie As New InternetExplorer, btn As Object, items As Object, i As Long
With ie
.Visible = True
.Navigate2 "https://www.boerse-stuttgart.de/en/tools/product-search/bonds"
While .Busy Or .readyState < 4: DoEvents: Wend
Do
Loop Until .document.querySelectorAll(".bsg-loader-ring__item").Length = 0
.document.querySelector("#bsg-filters-btn-bgs-filter-3").Click
.document.querySelector("#bsg-checkbox-3053").Click
Set btn = .document.querySelector("#bsg-filters-menu-bgs-filter-3 .bsg-btn__label")
Do
Loop While btn.innerText = "Close"
btn.Click
Do
Loop Until .document.querySelectorAll(".bsg-loader-ring__item").Length = 0
Dim count As Long
Do
On Error Resume Next
Set items = .document.querySelectorAll(".bsg-table__tr td:first-child")
count = items.Length
On Error GoTo 0
Loop While count = 0
For i = 0 To items.Length - 1
Debug.Print items.item(i).innerText
Next
.Quit
End With
End Sub