Skip to content

Instantly share code, notes, and snippets.

/test.pl Secret

Created April 14, 2012 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/29de1f3e6fa26dcd3cff to your computer and use it in GitHub Desktop.
Save anonymous/29de1f3e6fa26dcd3cff to your computer and use it in GitHub Desktop.
はてな用
#!"C:\xampp\perl\bin\perl.exe"
print "Content-type: text/html; charset=UTF-8\n\n";
use strict;
use warnings;
use Web::Scraper;
use Data::Dumper;
use URI;
my $url = URI->new('http://yugioh.wikia.com/wiki/Blue-Eyes_White_Dragon');
my $res = scraper {
process '//div/table[1]', 'table[]' => 'HTML';
process '//div/table[1]//tr/th', 'th[]' => 'TEXT';
}->scrape($url); #URLに変える
my $th_position;
for (my $i=0; $i < $res->{th}; $i++ ) {
if ($res->{th}[$i] eq "Japanese") {
$th_position = $i;
last;
}
}
my $table_html = $res->{table}[0];
my $res2 = scraper {
process '//td[' . ($th_position + 1) . ']', 'td[]' => 'TEXT'
}->scrape($table_html);
print Dumper $res2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment