亲爱的stackoverflowers,
我是VBA的新手,我尝试从受密码保护的网站获取一些数据。 填写用户名和密码,然后单击提交按钮工作正常。然后,打开另一个页面,我必须点击几个按钮'但我不明白为什么它不起作用。 我尝试点击以下图标。
<td class="menuitem"> <a title="Klik hier voor de dienst Kadaster-on-line" class="navig" onmouseover="return s_('Kadaster-on-line')" onmouseout="return s_()" href="https://kadaster-on-line.kadaster.nl/default.asp" target="_parent">Kadaster-on-line</a>
到目前为止,代码的第一部分工作
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButtons As MSHTML.IHTMLElementCollection
Dim HTMLButton As MSHTML.IHTMLElement
Dim HTMLAs As MSHTML.IHTMLElementCollection
Dim HTMLA As MSHTML.IHTMLElement
IE.Visible = True
IE.navigate "https://mijn.kadaster.nl/security/login.jsp"
Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
Set HTMLDoc = IE.Document
Set HTMLInput = HTMLDoc.getElementById("gebruikerscode")
HTMLInput.Value = "username"
IE.Document.forms("myform").elements("wachtwoord").Value = "password"
IE.Document.forms("myform").elements("inloggen").Click
Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop
但第二部分不起作用。首先,我试图通过getelementsbyclassname来解决它,但我想它应该通过标记名来实现
Set HTMLAs = HTMLDoc.getElementsByTagName("td")
'For Each HTMLA In HTMLAs
Debug.Print HTMLAs.Length
'Next
似乎代码无法识别标记名&#34; td&#34; 我还尝试使用classname&#34; menuitem&#34;
的代码 有人可以帮帮我吗?亲切的问候
答案 0 :(得分:2)
您需要重新执行
Set HTMLDoc = IE.Document
加载新页面后。否则HTMLDoc仍然指向上一页(不再可用......)