我正在尝试使用 vba 自动化 Internet Explorer,下面是我的代码:
Sub go_IE()
Dim objIE As SHDocVw.InternetExplorer
Dim htmlColl As MSHTML.IHTMLElementCollection
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlDoc As MSHTML.HTMLDocument
Set objIE = New SHDocVw.InternetExplorer
objIE.Visible = True
objIE.Navigate "example.com/abc/home/" 'load web page google.com
While objIE.Busy
DoEvents 'wait until IE is done loading page.
Wend
Set htmlDoc = objIE.Document 'htmlDoc now holds home page
Set htmlColl = htmlDoc.getElementsByTagName("button")
For Each htmlInput In htmlColl
If htmlInput.Type = "submit" Then
htmlInput.Click ' click on the submit button
End If
Next htmlInput
While objIE.Busy
DoEvents 'wait until IE is done loading page.
Wend
Set htmlDoc = objIE.Document
Set htmlColl = htmlDoc.getElementsByTagName("button")
For Each htmlInput In htmlColl
If htmlInput.Type = "submit" Then
htmlInput.Click ' click on the submit button
End If
Next htmlInput
While objIE.Busy
DoEvents 'wait until IE is done loading page.
Wend
objIE.Quit
End Sub
一旦我点击主页并导航到下一页,下面的行没有给我任何东西:
Set htmlDoc = objIE.Document
它只是说权限被拒绝。
我做了很少的研究,发现这与同源政策有关。但是我检查了,点击主页中的提交按钮后,网址没有改变。
任何机构可以帮助我解决这个问题或任何建议吗?