Get URL of page in Internet Explorer using Powersh

2019-08-30 01:31发布

问题:

I have a PowerShell script which will open an instance of internet explorer, go to a certain website and find a hidden link but when I go to that link it redirects me to another page.

I'd like to find the URL of the page that internet explorer is now in to be stored in a variable.

Thanks!

For those who only read code:

$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.

回答1:

So if you are trying to get the current location of a document then you can use : $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