-
-
Save anonymous/e329f07eca6b0f894162 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
[jdv@wieldy ~]$ cat test_login_gh.pl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use HTML::TreeBuilder; | |
my ( $user, $pass, ) = @ARGV; | |
my $ua = LWP::UserAgent->new( | |
requests_redirectable => [ 'GET', 'HEAD', 'POST' ]); | |
$ua->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" }); | |
my $html = HTML::TreeBuilder->new_from_content( | |
$ua->get('https://github.com/login')->decoded_content); | |
my %form = map { | |
$_->attr('type') eq 'submit' ? () : ($_->attr('name'), $_->attr('value')); | |
} $html->look_down(qw(_tag form action /session))->look_down(qw(_tag input)); | |
@form{qw(login password)} = ($user, $pass); | |
my $resp = $ua->post( 'https://github.com/session', \%form ); | |
print +($resp->decoded_content =~ /Signed in as.*jdv/ ? "" : "Not ") | |
. "Logged In\n"; | |
[jdv@wieldy ~]$ |
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
[jdv@wieldy ~]$ cat test_login_gh.p6 | |
use v6; | |
use HTML::Parser::XML; | |
use HTTP::UserAgent; | |
my ($user, $pass) = @*ARGS; | |
my $ua = HTTP::UserAgent.new; | |
my $html = HTML::Parser::XML.new.parse( | |
$ua.get('https://github.com/login').content); | |
my %form; | |
%form{.<name>} = .<value> | |
for $html.getElementsByTagName('form').[1].elements(:TAG<input>, :RECURSE); | |
%form{<< login password>>} = ($user,$pass); | |
say %form; | |
my $resp = $ua.request( | |
HTTP::Request.new(POST => 'https://github.com/session', |%form)); | |
say $resp.perl; | |
[jdv@wieldy ~]$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment