Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Parsing Web content

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-08-2007   #1 (permalink)
natebruneau
Guest


 

Parsing Web content

I am trying to download the code of a website and put it in a string.

I am getting this new error however:

$wc = new-object System.Net.WebClient
$wc.Headers.Add("user-agent", $userAgent)
$wc.DownloadString("http://google.com")

Exception calling "DownloadString" with "1" argument(s): "An exception
occurred
during a WebClient request." At line:1 char:19
+ $wc.DownloadString( <<<< "http://google.com")


Any ideas? I think this code worked fine on my other machine but not
this one (my laptop).

Thanks,

Nate


My System SpecsSystem Spec
Old 09-08-2007   #2 (permalink)
Shay Levi
Guest


 

Re: Parsing Web content

Works fine for me. Did you try any other URLs?

Shay
http://scriptolog.blogspot.com


Quote:

> I am trying to download the code of a website and put it in a string.
>
> I am getting this new error however:
>
> $wc = new-object System.Net.WebClient
> $wc.Headers.Add("user-agent", $userAgent)
> $wc.DownloadString("http://google.com")
> Exception calling "DownloadString" with "1" argument(s): "An exception
> occurred
> during a WebClient request." At line:1 char:19
> + $wc.DownloadString( <<<< "http://google.com")
> Any ideas? I think this code worked fine on my other machine but not
> this one (my laptop).
>
> Thanks,
>
> Nate
>
n


My System SpecsSystem Spec
Old 09-08-2007   #3 (permalink)
Hal Rottenberg
Guest


 

Re: Parsing Web content

natebruneau@xxxxxx wrote:
Quote:

> $wc = new-object System.Net.WebClient
> $wc.Headers.Add("user-agent", $userAgent)
> $wc.DownloadString("http://google.com")
>
> Exception calling "DownloadString" with "1" argument(s): "An exception
> occurred
> during a WebClient request." At line:1 char:19
> + $wc.DownloadString( <<<< "http://google.com")
What's $userAgent set to? This error could be a 500 thrown because of an
unrecognized user agent string. I'd tell you how to obtain the http status code
but I never figured out the best way to do it with WebClient. Instead, you
could try the same thing using XmlHttp and see what it returns.

$url = "http://www.cnn.com"
$xHTTP = new-object -com msxml2.xmlhttp;
$xHTTP.open("GET",$url,$false);
$xHTTP.send();
$xHTTP.ResponseText; # returns the html doc like downloadstring
$xHTTP.status # returns the status code
$xHTTP.statusText # status error text

--

Hal Rottenberg
blog: http://halr9000.com
powershell category:
http://halr9000.com/article/category...ng/powershell/
My System SpecsSystem Spec
Old 09-09-2007   #4 (permalink)
Shay Levi
Guest


 

Re: Parsing Web content

I ran it "as-is" even with $userAgent (which equals to $null) and I still
can get the web page.

Shay
http://scriptolog.blogspot.com


Quote:

> natebruneau@xxxxxx wrote:
>
Quote:

>> $wc = new-object System.Net.WebClient
>> $wc.Headers.Add("user-agent", $userAgent)
>> $wc.DownloadString("http://google.com")
>> Exception calling "DownloadString" with "1" argument(s): "An
>> exception
>> occurred
>> during a WebClient request." At line:1 char:19
>> + $wc.DownloadString( <<<< "http://google.com")
> What's $userAgent set to? This error could be a 500 thrown because of
> an unrecognized user agent string. I'd tell you how to obtain the
> http status code but I never figured out the best way to do it with
> WebClient. Instead, you could try the same thing using XmlHttp and
> see what it returns.
>
> $url = "http://www.cnn.com"
> $xHTTP = new-object -com msxml2.xmlhttp;
> $xHTTP.open("GET",$url,$false);
> $xHTTP.send();
> $xHTTP.ResponseText; # returns the html doc like downloadstring
> $xHTTP.status # returns the status code
> $xHTTP.statusText # status error text

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Set-Content not updating file after get-content and forEach-Object Tolli PowerShell 1 06-14-2007 09:01 PM
EMC and Microsoft Form New Enterprise Content Management Alliance, Extend Microsoft Office SharePoint Server With Content, Compliance and Archive Solutions z3r010 Vista News 0 10-03-2006 08:04 AM
Issue: getting/setting variable content using Get/Set-Content =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 1 09-23-2006 04:09 AM
Weirdness with get-content | replace | set-content - file content is deleted!! Andrew Watt [MVP] PowerShell 4 05-23-2006 05:59 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51