Chinaunix

标题: 如何自动登录一个web系统,然后post提交数据 [打印本页]

作者: 99超人    时间: 2016-11-26 15:04
提示: 作者被禁止或删除 内容自动屏蔽
作者: Perl_Er    时间: 2016-11-26 18:43
  1. use strict;
  2. use warnings;
  3. use utf8;
  4. use LWP::UserAgent;
  5. use Data::Dumper;

  6. my $ua = LWP::UserAgent->new;
  7. $ua->timeout(10);
  8. $ua->env_proxy;

  9. my $req = HTTP::Request->new(GET => "http://rabbitmq01.sample.net:15672/api/vhosts");
  10. $req->authorization_basic('guest', 'guest');

  11. print $ua->request($req)->as_string;
复制代码

作者: Perl_Er    时间: 2016-11-26 18:46
  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;
  4. use HTTP::Request;
  5. use HTTP::Cookies;
  6. use LWP::UserAgent;

  7. my $url = 'http://passport.renren.com/PLogin.do';

  8. # 用来存 cookie
  9. my $cookie_jar = HTTP::Cookies->new(
  10.     file     => "./acookies.lwp",
  11.     autosave => 1,
  12. );

  13. # 给处理 cookie 的对象放到 LWP::UserAgent 中来处理 cookie
  14. # 登陆中
  15. my $ua      = LWP::UserAgent->new;
  16. my $cookies = $ua->cookie_jar($cookie_jar);
  17. $ua->agent('Mozilla/9 [en] (Centos; Linux)');
  18. my $res = $ua->post(
  19.     $url,
  20.     [
  21.         email    => 'username@gmail.com',
  22.         password => 'passwd',
  23. #        origURL  => 'http//www.renren.com/home',
  24. #        domain   => 'renren.com',
  25.     ],
  26. );

  27. #Now you can access your protected content

  28. #$res =$ua->get('http://www.renren.com/home.do');
  29. $res = $ua->get(
  30.     'http://blog.renren.com/blog/702740495/932392877?myblog'
  31. );
  32. print $res->content();
复制代码

作者: 99超人    时间: 2016-11-27 06:42
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2