-
-
Save anonymous/29de1f3e6fa26dcd3cff 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
#!"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