Created
October 10, 2011 11:33
-
-
Save zyun53/1275093 to your computer and use it in GitHub Desktop.
nikkei login
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
use strict; | |
use warnings; | |
use Data::Dumper; | |
use WWW::Mechanize; | |
use HTML::TreeBuilder::XPath; | |
my $url = 'http://yahoo.jp'; | |
my $agentstr = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1'; | |
my $mech = new WWW::Mechanize( autocheck => 1, agent => $agentstr ); | |
# cookies | |
#my $cookie_file = "./nikkei_cookie"; | |
#$mech->cookie_jar->{ignore_discard} = 1; | |
#if( -e $cookie_file ) { | |
# $mech->cookie_jar->load($cookie_file); | |
#} | |
# Top -> loginForm | |
$mech->get('http://www.nikkei.com/'); | |
$mech->follow_link(url_regex => qr{/etc/accounts/login}); | |
# ログインページを探してたどっていく、ドケチな日経 | |
# 1st | |
$mech->submit_form( | |
form_name => 'autoPostForm', | |
); | |
my $tree = new HTML::TreeBuilder(); | |
$tree->parse($mech->content); | |
my @items = $tree->look_down('id','javax.faces.ViewState'); | |
my $java = $items[0]->attr('value'); | |
@items = $tree->look_down('name','controlParamKey'); | |
my $pri = $items[0]->attr('value'); | |
#foreach my $form ($mech->forms) { | |
# foreach my $input ($form->inputs) { | |
# printf("%s (%s) : %s\n", $input->name, $input->type, $input->value); | |
# } | |
#} | |
$mech->submit_form( | |
form_name => 'LA0210Form01', | |
fields => { | |
'LA0210Form01:LA0210Email' => $email, | |
'LA0210Form01:LA0210Password' => $password, | |
}, | |
button => 'LA0210Form01:j_id29', | |
); | |
$mech->submit_form( | |
); | |
$mech->get('http://www.nikkei.com/paper/'); | |
# | |
#die "SUBMIT failed\n" unless $result->is_success; | |
print $mech->content; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment