7.11. Downloading Content from the WebThe System.Net.WebClient class offers a DownloadString method that can be used to pull content directly from a URL. Because these examples are pulled from dynamic content on the Internet, the exact values in the output may change over time: MSH D:\MshScripts> $wc = new-object System.Net.WebClient MSH D:\MshScripts> $content = $wc.DownloadString("http://www.oreilly.com") MSH D:\MshScripts> $content | measure-object -words -lines -characters Lines Words Characters Property ----- ----- ---------- -------- 1108 4554 54957 WebClient is not particular about the type of content it downloads. If a URL points to XML content, it is perfectly legitimate to cast the string to an XmlDocument and work with it from there: MSH D:\MshScripts> $xml = [Xml]$wc.DownloadString ("http://www.oreillynet.com/rss/render/160.rss") MSH D:\MshScripts> $xml.GetElementsByTagName("item") | format-table title title ----- Exchange Server Cookbook ASP.NET 2.0: A Developer's Notebook Knoppix Pocket Reference Firefox Secrets: A Need-to-Know Guide Mapping Hacks Mac OS X Tiger Pocket Guide Learning Unix for Mac OS X Tiger Assembling Panoramic Photos: A Designer's Notebook DHTML Utopia: Modern Web Design Using JavaScript and DOM Toad Pocket Reference for Oracle, 2nd Edition Mac OS X Tiger for Unix Geeks |