2013年9月26日木曜日

◆Invoke-WebRequestサンプル2

PowerShell: ◆Invoke-WebRequestサンプル

 

Invoke-WebRequestで取ってきた後、ParsedHtmlプロパティを使うと自分でHTML解析せずに色々と使えそう。

私自身Web系のプログラミングはやらないので詳しくは判らないが、さしあたってタグとその順番を指定して切り出すには以下のような感じ。

001
002
003
004
005
006
007
008
009

$URL = "http://weather.yahoo.co.jp/weather/jp/3/3310.html"
$OutputFile = "$env:temp\weather.html"

$data = Invoke-WebRequest -Uri $URL
 
@(
$data.ParsedHtml.getElementsByTagName("h2"))[0].OuterHTML ,
@($data.ParsedHtml.getElementsByTagName("table"))[0].OuterHTML |
Set-Content -Path $OutputFile

& $OutputFile

<切り出し前>

image

<切り出し後>

image