Created
October 1, 2012 10:45
-
-
Save tsurumau/3810888 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Carp; | |
use LWP::UserAgent; | |
my $ua = LWP::UserAgent->new; | |
my @keys; | |
for my $n ('01'..'99') { | |
my $uri = "http://www.symphogear.com/key$n.html"; | |
my $res = $ua->get($uri); | |
if ($res->code == 404) { | |
last; | |
} | |
if ($res->is_success) { | |
my $html = $res->decoded_content; | |
my ($title, $body) = $html =~ m!<h2>(.+?)</h2>.*?<p class="key">(.+?)</p>!s; | |
push @keys, [$title, $body]; | |
} else { | |
croak "GET " . $res->request->uri . " failed: ", $res->status_line; | |
} | |
} | |
local $/ = '<!--KEYWORDS-->'; | |
print <DATA> | |
. join("\n", map "<dt>$_->[0]</dt><dd>$_->[1]</dd>", @keys) | |
. <DATA>; | |
__END__ | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>KEYWORDS</title> | |
<style type="text/css"> | |
body { | |
font: 12px Osaka,Meiryo,sans-serif; | |
color: #FFFFFF; | |
background: #000000; | |
line-height:28px; | |
} | |
dt { | |
clear: left; | |
float: left; | |
margin: 0 0 0.8em; | |
border-left: solid 8px #CCC; | |
padding-left: 6px; | |
} | |
dd { | |
margin-bottom: 0.8em; | |
margin-left: 15em; | |
} | |
</style> | |
</head> | |
<body> | |
<dl> | |
<!--KEYWORDS--> | |
</dl> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment