/* ]]> */
Jan 062011
 

This is so incredibly easy. With only three simple lines of code, you can capture all the HTML content from a web page.

Are you ready?

Here goes:

?View Code POWERSHELL
$webclient = new-object system.net.WebClient
$webpage = $webclient.DownloadData("http://www.google.com/#q=poshtips.com")
$pagedata = [System.Text.Encoding]::ASCII.GetString($webpage)

The contents of the specified web page will be contained in the $pagedata variable.

To save the page contents to a file, simply add one more line of code as follows:

?View Code POWERSHELL
$webclient = new-object system.net.WebClient
$webpage = $webclient.DownloadData("http://www.google.com/#q=poshtips.com")
$pagedata = [System.Text.Encoding]::ASCII.GetString($webpage)
$pagedata | out-file "googlesearch.html"

That’s all there is to it.

 Posted by at 11:25 am

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Page optimized by WP Minify WordPress Plugin