<pre name="code" class="html">use Net::SMTP;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use File::Temp qw/tempfile/;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $ua = LWP::UserAgent->new;
$ua->timeout(5);
my $cookie_jar = HTTP::Cookies->new(
file=>'ty_lwp_cookies.txt',
autosave=>1,
ignore_discard=>1
);
$ua->cookie_jar($cookie_jar);
my $response = $ua->get('https://account.tingyun.com/cas/login?service=https%3A%2F%2Fsaas.tingyun.com%2Fj_acegi_cas_security_check%3FloginView%3DcasLoginTingyun');
open DATAFH,">data.html" || die "open data file failed:$!";
if ($response->is_success) {
#print DATAFH $response->decoded_content; # or whatever
print DATAFH $response->content; # or whatever
}
close DATAFH;
use HTML::TreeBuilder::XPath;
$tree= HTML::TreeBuilder::XPath->new;
$tree->parse_file("data.html");
my @pages=$tree->find_by_tag_name('input');
#@urlall除了包含每个类别的文章,还包含阅读排行里的文章
foreach (@pages) {
@titlepage = $_->attr('value');
foreach (@titlepage) {
chomp $_;
if ($_){
print "\$_ is $_\n";
$it_tag=$_;
};
};
##退出当前循环:
last;
};
print "\$it_tag is $it_tag\n";
sleep(2);
my $login_url = 'https://account.tingyun.com/cas/login?service=https%3A%2F%2Fsaas.tingyun.com%2Fj_acegi_cas_security_check%3FloginView%3DcasLoginTingyun&lang=zh_CN';
#my $login_url = 'https://account.tingyun.com/cas/login?service=https://saas.tingyun.com/j_acegi_cas_security_check?loginView=casLoginTingyun&lang=zh_CN';
my $res = $ua->post($login_url,{
_eventId=>'submit',
lt=>"$it_tag",
password=>'76ede6846c35b6e1aec36ad4cf65a9e1',
username=>'server@quvideo.com'
},
'User-Agent'=>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0',
'Host'=>'account.tingyun.com',
'Referer'=>"https://account.tingyun.com/cas/login?service=https%3A%2F%2Fsaas.tingyun.com%2Fj_acegi_cas_security_check%3FloginView%3DcasLoginTingyun",
'Upgrade-Insecure-Requests'=>1
);
print $res->status_line . "\n";
print $res->as_string();#获取的是原始内容,包括响应头,响应正文
my $url='https://saas.tingyun.com/j_acegi_cas_security_check?loginView=casLoginTingyun';
my $response = $ua->get($url);
print "--------------------\n";
# 判断响应头里面的location,确定是否登陆成功
print $res->header('Location');
print "\n";
jrhmpt01:/root# perl ty.pl
$_ is _cFD65326B-19A2-35BE-8DAC-BEC685FC65F1_kFFC533A8-238E-8CF2-9D73-8FF512527691
$it_tag is _cFD65326B-19A2-35BE-8DAC-BEC685FC65F1_kFFC533A8-238E-8CF2-9D73-8FF512527691
302 Found
HTTP/1.1 302 Found
Cache-Control: no-cache
Cache-Control: no-store
Connection: close
Date: Thu, 22 Sep 2016 07:29:04 GMT
Pragma: No-cache
Location: https://saas.tingyun.com/j_acegi_cas_security_check?loginView=casLoginTingyun&ticket=ST-114612-1D4vn5gJHAgcD4jCDiLEXpeXrUbSDydQagr-account.tingyun.com
Server: Tengine
Content-Language: zh-CN
Content-Length: 0
Content-Type: text/html;charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Access-Control-Allow-Headers: accept, content-type, classname
Access-Control-Allow-Origin: *
Client-Date: Thu, 22 Sep 2016 07:29:04 GMT
Client-Peer: 123.103.75.4:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/O=GeoTrust Inc./CN=GeoTrust SSL CA - G3
Client-SSL-Cert-Subject: /C=CN/ST=beijing/L=beijing/O=\xE5\x8C\x97\xE4\xBA\xAC\xE5\x9F\xBA\xE8\xB0\x83\xE7\xBD\x91\xE7\xBB\x9C\xE8\x82\xA1\xE4\xBB\xBD\xE6\x9C\x89\xE9\x99\x90\xE5\x85\xAC\xE5\x8F\xB8/OU=IT dept./CN=*.tingyun.com
Client-SSL-Cipher: ECDHE-RSA-AES256-SHA
Client-SSL-Warning: Peer certificate not verified
Set-Cookie: org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=zh_CN; Expires=Tue, 10-Oct-2084 10:43:11 GMT; Path=/
Set-Cookie: CASPRIVACY=""; Domain=tingyun.com; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/cas
Set-Cookie: CASTGC=TGT-57918-uCE2mcdi4YDaiVTEUHpLY2ZbRQj0vGPmGEF-account.tingyun.com; Domain=tingyun.com; Path=/cas
--------------------
https://saas.tingyun.com/j_acegi_cas_security_check?loginView=casLoginTingyun&ticket=ST-114612-1D4vn5gJHAgcD4jCDiLEXpeXrUbSDydQagr-account.tingyun.com
<img src="//img-blog.csdn.net/20160922154030372?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<img src="//img-blog.csdn.net/20160922154040301?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
<img src="//img-blog.csdn.net/20160922154053403?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />