Created
June 18, 2012 02:24
-
-
Save eru/2946466 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/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Encode; | |
use WWW::Mechanize; | |
use Web::Scraper; | |
use YAML; | |
# 取得したい場所のYahoo!天気情報のURL | |
my $location_url = 'http://weather.yahoo.co.jp/weather/jp/8/4010.html'; | |
# 初期化,取得 | |
my $mech = WWW::Mechanize->new(autocheck => 1); | |
$mech->get($location_url); | |
# スクレイピング設定 | |
my $scraper = scraper { | |
process 'h1.yjM', 'location' => 'TEXT'; | |
process 'table.yjw_table[cellpadding="4"]', 'day[]' => scraper { | |
process 'table > tr > td > b', 'date' => 'TEXT'; | |
process 'table > tr > td > img', 'weather' => '@alt'; | |
process 'table > tr > td > small > font[color="#ff3300"]', 'temp_max' => 'TEXT'; | |
process 'table > tr > td > small > font[color="#0066ff"]', 'temp_min' => 'TEXT'; | |
process 'table.yjw_table3_s > tr[bgcolor="#e9eefd"] > td[width="18%"]', 'precipitation[]' => 'TEXT'; | |
process 'table.yjw_table3_s > tr[bgcolor="#eeeeee"] > td[width="18%"]', 'time_band[]' => 'TEXT'; | |
}; | |
}; | |
# スクレイピング | |
my $weather_data = $scraper->scrape($mech->content()); | |
print encode_utf8(YAML::Dump($weather_data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment