国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PowerShell > 正文

PowerShell小技巧實現IE Web自動化

2020-03-26 19:17:12
字體:
來源:轉載
供稿:網友

Windows 系統自帶的Internet Explore +加上PowerShell 即可搞定。

今天就分享下這幾天自己寫的幾個小函數,歡迎拍磚:

## 打開IE窗口#function New-IEWindow{  param(  [string]$Url,  [switch]$Visible,  [switch]$FullScreen  )  $Global:IEHost = new-object -com "InternetExplorer.Application"  $Global:IEHost.Navigate($Url)   #設置IE可見性和全屏  $Global:IEhost.Visible= $Visible  $Global:IEHost.FullScreen= $FullScreen   } ##等待IE加載完畢#function Wait-IEReady([int]$TimeoutSeconds=10){  $milliseconds=0  $maxMilliseconds = $TimeoutSeconds * 1000  while($Global:IEHost.Busy)  {       if($milliseconds -gt $maxMilliseconds)   {    throw 'Wait ie ready timeout.'   }   sleep -Milliseconds 100   $milliseconds+=100      }} ## 根據ID,Class,Name,Tag獲取HTML元素#function Get-HtmlElement ($Id,$Name,$Class,$Tag){ if($Id) {  return $IEHost.Document.getElementById($id) } elseif($Name) {  return $IEHost.Document.getElementsByName($Name) } elseif($Class) {  $IEHost.Document.all | where {$_.className -contains $Class} } elseif($Tag) {  $IEHost.Document.getElementsByTagName($Tag) }  } ##關閉IE窗口#function Close-IEWindow{  $Global:IEHost.quit()  Remove-Variable IEHost -Force} ##設置IE的地址#function Navigate-IE($Url){ Set-IE -URL $Url} ## 設置IE的地址,或者動作:前進,倒退,刷新#function Set-IE{ param( [ValidateSet('GoBack', 'GoForward','Refresh')] [string]$Action, [uri]$URL )  # 動作 switch($Action) { ('GoBack'){ $Global:IEHost.GoBack() } ('GoForward'){ $Global:IEHost.GoForward() } ('Refresh'){ $Global:IEHost.Refresh() } }  # 設置IE地址 if( $URL) { $Global:IEHost.Navigate($URL) }} ## 在IE窗口中執行腳本#function Invoke-IEScript($Code,$Language='Javascript'){ if( -not [string]::IsNullOrWhiteSpace($Code)) { $Global:IEHost.Document.parentWindow.execScript($Code,$Language) }}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张掖市| 四会市| 余庆县| 新建县| 呈贡县| 南丹县| 浦北县| 突泉县| 石景山区| 沂源县| 自贡市| 扶风县| 安丘市| 益阳市| 泰和县| 萝北县| 沂水县| 鄂托克前旗| 武定县| 新余市| 珲春市| 开平市| 卓尼县| 都昌县| 沂南县| 长葛市| 张北县| 宝山区| 绍兴县| 双鸭山市| 穆棱市| 南投市| 永仁县| 沂水县| 交口县| 阿瓦提县| 沙洋县| 四川省| 甘孜| 垣曲县| 黄浦区|