2015年(5)
分类: 系统运维
2015-07-02 09:11:43
Function GetCurrentIEURL
{
$IEObjs = @()
$ShellWindows = (New-Object -ComObject Shell.Application).Windows()
Foreach($IE in $ShellWindows)
{
$FullName = $IE.FullName
If($FullName -ne $NULL)
{
$FileName = Split-Path -Path $FullName -Leaf
If($FileName.ToLower() -eq "iexplore.exe")
{
$Title = $IE.LocationName
$URL = $IE.LocationURL
$IEObj = New-Object -TypeName PSObject -Property @{Title = $Title; URL = $URL}
$IEObjs += $IEObj
}
}
}
$IEObjs
}
来抓取那一瞬间产生的文件路径.下面就通过判断抓取的路径进行下载.
$latenote = $ie.Document.getElementById("latnote")
Invoke-WebRequest -uri $src+".csv" -OutFile $destination
Function DownloadTestResults()
{
$ie = New-Object -COM InternetExplorer.Application
$ie.Navigate("
while( $ie.busy){Start-Sleep 1}
Write-Host $latenote
$downloadresults = $ie.Document.getElementById("drbt")
while( $ie.busy){Start-Sleep 10}
Start-Sleep -s 100
$downloadresults.click()
$CurrentIEURL = GetCurrentIEURL
If($CurrentIEURL -ne "
Write-Host "Successfully exported csv file on '$ExportCsvFile'"
$src = $null
Import-Csv C:\Users\Public\1.csv|Where-Object {
if($_.URL -eq $_.Title){
$src = $_.URL
Write-Host $_.URL
}
}
#$src = ''
$date = Get-Date
$name = $date.ToString('yyyy-MM-dd-hh-mm')
#Destination Folder
$destination = New-Item -Path c:\users\public\PACResults\$name.csv -ItemType file -Force
Unblock-File $destination
}
Else
{
Write-Warning "Can not find any URL of Tab."
}
}