Changeset 231
- Timestamp:
- 03/02/06 09:54:09
- Files:
-
- trunk/plagger/lib/Plagger/Cache.pm (modified) (2 diffs)
- trunk/plagger/lib/Plagger/CacheProxy.pm (modified) (1 diff)
- trunk/plagger/lib/Plagger/Plugin/CustomFeed/Yahoo360JP.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Cache.pm
r225 r231 2 2 use strict; 3 3 use File::Spec; 4 use HTTP::Cookies; 4 5 use UNIVERSAL::require; 5 6 … … 62 63 } 63 64 65 sub cookie_jar { 66 my($self, $ns) = @_; 67 my $file = $ns ? "global.dat" : "$ns.dat"; 68 69 my $dir = File::Spec->catfile($self->{base}, 'cookies'); 70 mkdir $dir, 0755 unless -e $dir && -d _; 71 72 return HTTP::Cookies->new( 73 file => File::Spec->catfile($dir, $file), 74 autosave => 1, 75 ); 76 } 77 64 78 1; trunk/plagger/lib/Plagger/CacheProxy.pm
r225 r231 20 20 } 21 21 22 sub cookie_jar { 23 my $self = shift; 24 $self->{cache}->cookie_jar($self->{namespace}); 25 } 26 22 27 1; trunk/plagger/lib/Plagger/Plugin/CustomFeed/Yahoo360JP.pm
r226 r231 28 28 my($self, $context, $args) = @_; 29 29 30 # TODO: save cookies31 my $start = "https://login.yahoo.co.jp/config/login?.src=360&.done=http%3A%2F%2F360.yahoo.co.jp%2F%3F.login%3D1"; # SSL 32 33 my $mech = WWW::Mechanize->new;30 my $start = "http://360.yahoo.co.jp/"; 31 32 my $mech = WWW::Mechanize->new(cookie_jar => $self->cache->cookie_jar); 33 $mech->agent_alias( 'Windows IE 6' ); 34 34 $mech->get($start); 35 $mech->submit_form( 36 fields => { 37 login => $self->conf->{username}, 38 passwd => $self->conf->{password}, 39 '.persistent' => 'y', 40 }, 41 ); 42 43 if ($mech->content =~ m!<span class="error">!) { 44 $context->log(error => "Login to Yahoo! failed."); 45 return; 35 36 if ($mech->content =~ /mgb_login/) { 37 $self->login($mech) or return; 46 38 } 47 39 … … 142 134 } 143 135 136 sub login { 137 my($self, $mech) = @_; 138 139 $mech->submit_form( 140 fields => { 141 login => $self->conf->{username}, 142 passwd => $self->conf->{password}, 143 '.persistent' => 'y', 144 }, 145 ); 146 147 while ($mech->content =~ m!<span class="error">!) { 148 Plagger->context->log(error => "Login to Yahoo! failed."); 149 if ($mech->content =~ m!(https://captcha.yahoo.co.jp/img/.*\.jpg)!) { 150 my $captcha = $self->prompt_captcha($1) or return; 151 $mech->submit_form( 152 fields => { 153 login => $self->conf->{username}, 154 passwd => $self->conf->{password}, 155 '.secword' => $captcha, 156 '.persistent' => 'y', 157 }, 158 ); 159 } else { 160 return; 161 } 162 } 163 164 return 1; 165 } 166 144 167 sub add_entry { 145 168 my($self, $feed, $args, $now, $format) = @_; … … 179 202 } 180 203 204 sub prompt_captcha { 205 my($self, $url) = @_; 206 print STDERR "CAPTCHA:\n$url\nEnter the code: "; 207 208 # use alarm timeout for cron job 209 my $key; 210 eval { 211 local $SIG{ALRM} = sub { die "alarm\n" }; 212 alarm 30; 213 chomp($key = <STDIN>); 214 alarm 0; 215 }; 216 return if $@; 217 218 return $key; 219 } 220 181 221 1; 182 222
