LeVeilleur.net

Subscribe

PowerShell : Save Html, Body, ….

février 10, 2009 By: Christopher Keyaert Category: Non classé 1 Comment →

Voici trois méthodes permettant de sauver une page web ou plus simplement du code html

# Internetexplorer.application
$obj=New-Object -ComObject internetexplorer.application
$obj.visible=$true
$obj.navigate2("http://www.google.com")
while($obj.ReadyState -ne 4){start-sleep -m 100}
$obj.Document.documentElement.outerHTML

# xml http
$url = "http://www.cnn.com"
$xHTTP = new-object -com msxml2.xmlhttp;
$xHTTP.open("GET",$url,$false);
$xHTTP.send();
$xHTTP.ResponseText; # returns the html doc

# net.webclient
$url="http://www.cnn.com"
$wc = new-object net.webclient
$html = $wc.DownloadString($url)

PowerShell : Control IE

février 03, 2009 By: Christopher Keyaert Category: powershell No Comments →

Voici quelques bouts de code PowerShell permettant le control d’Internet Explorer

#Rune IE
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate('http://mypage.com')

#Authentication on the web page
while($ie.busy) {start-sleep 1}
if ($ie.document.getElementByID("FormUsername") -ne $null)
    {
    $ie.document.getElementByID("FormUsername").value = "myLogin"
    $ie.document.getElementByID("FormPassword").value = "MyPwd"

    #Click on the button for logon
    $forms = @($ie.Document.forms | where {$_.action -match "VerifPwd.htm"})
    $forms[0].submit()
    while($ie.busy) {start-sleep 1}
    }

$ie.navigate('http://mypage.com/page2.html')
while($ie.busy) {start-sleep 1} 

#Exit IE
$ie.quit()