The previous powershell script for dilbert broke. It seems the cartoons aren't sequential. This is try #2.
$url = "http://www.dilbert.com"
$httpRequest = [Net.WebRequest]::create($url)
$response = $httpRequest.GetResponse()
$stream = $response.GetResponseStream()
$buffer = @()
$binaryReader = New-Object System.IO.BinaryReader($stream)
$tempBuffer = $binaryReader.ReadBytes(1024)
while($tempBuffer.Length -eq 1024) {
$buffer += $tempBuffer
$tempBuffer = $binaryReader.ReadBytes(1024)
}
$dilbert = [System.Text.ASCIIEncoding]::UTF8.GetString($buffer)
$url = "http://www.dilbert.com/" + [System.Text.RegularExpressions.Regex]::Match($dilbert, "src=.*strip.gif").Value.Substring(5)
$url
$httpRequest = [Net.WebRequest]::create($url)
$response = $httpRequest.GetResponse()
$stream = $response.GetResponseStream()
$buffer = @()
$binaryReader = New-Object System.IO.BinaryReader($stream)
$tempBuffer = $binaryReader.ReadBytes(1024)
while($tempBuffer.Length -eq 1024) {
$buffer += $tempBuffer
$tempBuffer = $binaryReader.ReadBytes(1024)
}
$buffer += $tempBuffer
$tempFile = [System.IO.Path]::GetTempFileName() + ".gif"
[System.IO.File]::WriteAllBytes($tempFile, $buffer)
.$tempFile
No comments:
Post a Comment