Sunday, November 9, 2014

How to get gesamt.html with PowerShell

How to download the file gesamt.html from Heidegger Gesamtausgabe app at gesam.azurewebsites.net. The app will generate a fresh copy from its database. The PowerShell commands follow:

# Sends a sign-in request by running the Invoke-WebRequest cmdlet. The command specifies a value of "fb" for the SessionVariable parameter, and saves the results in the $r variable. 
$r=Invoke-WebRequest https://gesam.azurewebsites.net/Account/Login -SessionVariable fb -UseBasicParsing

$rVerificationToken=($r.InputFields | Where { $_.name -eq "__RequestVerificationToken" }).value

# Gets the first form in the Forms property of the HTTP response object in the $r variable, and saves it in the $form variable. 
$form = $r.Forms[0]

# The next two commands populate the values of the "email" and "pass" keys of the hash table in the Fields property of the form. Of course, you can replace the email and password with values that you want to use.  
$form.Fields["Email"] = "nemo@nowhere.com"
$form.Fields["Password"] = "password"
$form.Fields["__RequestVerificationToken"] = $rVerificationToken

# The final command uses the Invoke-WebRequest cmdlet to sign in to the web service.
$r=Invoke-WebRequest -Uri "https://gesam.azurewebsites.net/Account/Login" -WebSession $fb -Method POST -Body $form.Fields

# The above is based on the Invoke-WebRequest help. Now get the gesamt.html into $r
$r=Invoke-WebRequest -Uri "https://gesam.azurewebsites.net/Band/Print" -WebSession $fb -Method POST -Body $form.Fields

No comments:

Post a Comment