我有一个PowerShell脚本,它将打开Internet Explorer的实例,转到某个网站并找到一个隐藏的链接,但是当我转到该链接时,它会将我重定向到另一个页面。
我想找到互联网浏览器现在所在的页面的 URL 以存储在变量中。
谢谢!
对于那些只阅读代码的人:
$IE = new-object -com internetexplorer.application
$IE.visible = $true
$Document = $IE.navigate2("example.com")
# Do stuff
$Document = $IE.navigate2($LinkIFound)
# It redirects me...
# TODO: Find URL of page I am now in.
因此,如果您尝试获取文档的当前位置,则可以使用: $IE.Document.url
$IE = new-object -com internetexplorer.application
$IE.visible = $true
$Document = $IE.navigate2("example.com")
# Do stuff
$OldUrl = $IE.Document.url
$Document = $IE.navigate2($LinkIFound)
sleep -seconds 3
$NewUrl = $IE.Document.url