1)如何在PowerShell中使用Internet Explorer?
2)如何在私人模式中使用带有Powershell的Internet Explorer
答案 0 :(得分:3)
我看到很多关于如何使用Internet Explorer Com对象的问题 的powershell。
1)对象
中的Com对象/构建$IE=New-Object -com InternetExplorer.Application
表示通过IExplorer Application的Com对象创建新对象。
现在变量$ IE具有关于Internet Explorer的信息。
默认情况下,网站处于隐藏模式,因此我们需要将其更改为可见。
是这样的:
$IE.Visible=$true
要导航到其他网站,您可以使用导航功能:
$IE.Navigate("https://www.google.co.il/")
要检查网站已经完成重新加载网页,我们可以使用布尔值为True(尚未加载),False(完成加载)的成员/属性忙碌。
使用:
while ($IE.Busy -eq $true) {sleep -Seconds 2; }
您需要从IExplorer获取文档对象
$docs = $IE.Document
现在变量$ docs得到了Document对象。
现在你问:我应该在那里搜索什么?。
在Internet Explorer中单击F12并搜索“输入”选项卡检查:
现在我知道很多关于标签的信息。
让我在PowerShell中获取输入,我知道输入名称是" q", 所以让我们按名称搜索:(我们只想选择一个)
$InputTab = $docs.getElementsByName("q") | select -First 1
现在我们得到了输入,现在让我们输入一些内容:
$InputTab.value = "Your Value"
All in All Code:
$IE=New-Object -com InternetExplorer.Application
$IE.Visible=$true
$IE.Navigate("https://www.google.co.il/")
while ($IE.Busy -eq $true) {sleep -Seconds 2 }
$docs = $IE.Document
$InputTab = $docs.getElementsByName("q") | select -First 1
$InputTab.value = "Your Value"
2) 和IExplorer对象一样,我们有一个名为" Shell"的Com对象。 收集所有"跑步"应用程序
这意味着像IExplorer应用程序有更多应用程序,如资源管理器(文件夹视图)和越来越多的Com对象...
那么我如何使用Shell?以及我如何使用它与#34; PrivateMode"?
很容易
创建
$Shell = New-Object -Com Shell.Application
创建Shell对象,现在通过以下方式获取All Application:
$Application = $Shell.Windows()
现在
$ Application变量获得了所有的Com Applcation ..
所以只需要创建Iexplore"私人模式"然后获取该应用程序。
A)创建IExplore(只需使用私有模式运行正常流程)
Start-Process -FilePath "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -ArgumentList ' -private http://Url.Test.NotExist'
B)创建Shell App
$Shell = New-Object -Com Shell.Application
C)获取所有Shell对象
$Application = $Shell.Windows()
D)获取Shell的Internet Explorer应用程序
$IE = $Application | ?{$_.LocationName -like '*google*'} | select -last 1
我们现在完成$ IE在PrivateMode中得到了相同的(1)问题
最后)我真的推荐下载that
这将为您的文档对象添加功能,例如使用类名称和更多我发现有用的功能进行搜索