[英]VBA web scraping inserting value inside iFrame
我在访问 iFrame 中的项目时遇到问题。
IE.document.querySelector("[id='advanced_iframe']").contentDocument.querySelector("input[id=username]").Value = "ABC"
IE.document.querySelector("[id='advanced_iframe']").contentDocument.querySelector("input[type=submit]").Click
第一行是输入字段,第二行是提交按钮。
有趣的是,同样的代码在一个月前就有效了。 现在它只有在我停止代码时才有效,单击打开的 Internet Explorer window 或我要输入的字段,然后才继续输入代码。
上面两行之前的代码:
Dim i As Long
Dim url As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim HWNDSrc As Long
Dim destSheet As Worksheet
'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
url = "https://url"
'Navigate to URL
IE.navigate url
' Statusbar let's user know website is loading
Application.StatusBar = url & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertantly skipping over the second loop)
Do While IE.readyState = 4: DoEvents: Loop
Do Until IE.readyState = 4: DoEvents: Loop
'Webpage Loaded
Application.StatusBar = url & " Loaded"
'Get Window ID for IE so we can set it as activate window
HWNDSrc = IE.hWnd
'Set IE as Active Window
SetForegroundWindow HWNDSrc
'Login
IE.document.getElementById("log").Value = "Username"
IE.document.getElementById("pwd").Value = "Passwword"
Set g = IE.document.getElementsByName("Submit")
g(0).Click
On Error Resume Next
'Do Until IE.readyState = 4: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:10"))
'Insert value into text box inside the iframe
IE.document.querySelector("[id='advanced_iframe']").contentDocument.querySelector("input[name=username]").Value = "ABC"
IE.document.querySelector("[id='advanced_iframe']").contentDocument.querySelector("input[type=submit]").Click
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.