Last active
November 14, 2022 23:26
-
-
Save ynkdir/428cb7d8b69294bc61d7 to your computer and use it in GitHub Desktop.
太洋社 (http://taiyosha.co.jp/) のコミック発売予定一覧を取得して CSV を出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 太洋社 (http://taiyosha.co.jp/) のコミック発売予定一覧を取得する | |
# | |
# to get csv: | |
# taiyosha_comic.ps1 | ConvertTo-CSV | |
function ToUTF8($s) { | |
return [Text.Encoding]::UTF8.GetString([Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($s)) | |
} | |
function GetTable($url) { | |
$r = Invoke-WebRequest $url | |
# $r.ParsedHTML をそのまま使うと文字化けするので | |
$h = New-Object -ComObject "HTMLFile" | |
$h.IHTMLDocument2_write((ToUTF8 $r.Content)) | |
$rows = @() | |
foreach ($tr in $h.getElementsByTagName("tr")) { | |
$row = @() | |
foreach ($td in $tr.childNodes) { | |
$s = $td.innerText | |
if ($s -eq $null) { | |
$s = "" | |
} | |
$s = $s.Trim() | |
$s = $s.Replace("`r", "") | |
$s = $s.Replace("`n", "") | |
$row += $s | |
} | |
$rows += ,$row | |
} | |
return $rows | |
} | |
function ToPSObject($head, $row) { | |
$hash = @{} | |
for ($i = 0; $i -lt $head.Length; $i++) { | |
$hash[$head[$i]] = $row[$i] | |
} | |
return New-Object PSCustomObject -Property $hash | |
} | |
function GetTaiyoshaComic($ym) { | |
$rows1 = GetTable "http://www.taiyosha.co.jp/comic/comic${ym}_date1.html" | |
$rows2 = GetTable "http://www.taiyosha.co.jp/comic/comic${ym}_date2.html" | |
$rows = $rows1 + $rows2[1..$rows2.Length] | |
$head = $rows[0] | |
return $rows[1..$rows.Length] | ForEach-Object { ToPSObject $head $_ } | |
} | |
# 2015-08 => 1508 | |
$ym = $args[0] | |
if ($ym -eq $null) { | |
$ym = (Get-Date).ToString("yyMM") | |
} | |
GetTaiyoshaComic $ym |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment