参考此篇文章,在实际测试网站试验下,操作成功,可正常登录。
http://www.cnblogs.com/bugua/archive/2012/10/15/2724069.html
主要步骤为:
1.用火狐firebug抓包,找到登录时或登录后那个url底下的cookie,不确定哪个url时,对比下登录前和登录后的cookie有啥不同。
2.用web_add_cookie()这个函数把抓包出来的cookie都加上。
3.把抓出来的url用函数转换成脚本,如get请求转换成web_url()模式。由于测试网站无post请求,不确定是否需要把post请求也转换。
以下为测试的脚本,pc端登录; H5登录未测试通过,不知原因,也未报错,无从查起。
*******************************************************************88
Action()
{
web_url("111",
"URL=https://t.xxx.com/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST );
web_reg_find("Text=123",
"SaveCount=Welcome_Count",
"Search=Body",
LAST);
//JSESSIONID=83B9E7CE81EC1ECB18705583B4356823; token=39b8a7a6-54b9-47d1-a475-bb4aeec7c2d7; browse_version=%E5%85%B6%E5%AE%83; username=jilu1219; MR=3
//每天的cookie会变更,需重新抓取cookie
web_add_cookie("Hm_lvt_1a00ca6fad0a49ac1db104c350d98870=1490434404,1490577365; DOMAIN=t.xxx.com");//
web_add_cookie("JSESSIONID=512C70884EE2247DDD06F0ED9C453C62; DOMAIN=t.xxx.com");
web_add_cookie("token=201797b5-c519-4584-850f-0dab98bb0541; DOMAIN=t.xxx.com");
web_add_cookie("Hm_lpvt_1a00ca6fad0a49ac1db104c350d98870=1490577370; DOMAIN=t.xxx.com");//
web_url("login.jhtml",
"URL=https://t.xxx.com/login.jhtml",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=https://t.xxx.com/",
"Snapshot=t2.inf",
"Mode=HTML",
LAST );
//https://t.xxx.com/common/check_username_and_mobile_and_email.jhtml?username=jilu1219&_=1490443906348
//https://t.xxx.com/common/check_username_and_mobile_and_email.jhtml?username=zff001&_=1490444043837
//
web_url("2222", //此段可省略
"URL=https://t.xxx.com/common/check_username_and_mobile_and_email.jhtml?username=jilu1219&_=1490443906348",
"TargetFrame=",
"Resource=0",
"RecContentType=application/json;charset=UTF-8",
"Referer=https://t.xxx.com/login.jhtml",
"Snapshot=t3.inf",
"Mode=HTML",
LAST );
lr_think_time(15);
web_url("333",
"URL=https://t.xxx.com/member/index.jhtml",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=https://t.xxx.com/login.jhtml",
"Snapshot=t4.inf",
"Mode=HTML",
LAST );
// Check result
if (atoi(lr_eval_string("{Welcome_Count}")) > 0){ //--判断检查点是否已检查到
lr_output_message("Log on successful.");
}
else{
lr_error_message("Log on failed");
return(0);
}
//尝试pc登录后,打开H5地址是否会重定向,实际测试此段需删除
web_url("444",
"URL=https://t.xxx.com/m/member/index.jhtml",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t5.inf",
"Mode=HTML",
LAST );
//Hm_lvt_1a00ca6fad0a49ac1db104c350d98870=1490434404,1490577365; token=201797b5-c519-4584-850f-0dab98bb0541
//; JSESSIONID=512C70884EE2247DDD06F0ED9C453C62; Hm_lpvt_1a00ca6fad0a49ac1db104c350d98870=1490578936; username=jilu1219; MR=3; UM_distinctid=15b0d6d8edb130-042bb16955eba98-47524131-d7300-15b0d6d8edc4f6;
// CNZZDATA1261546442=206790962-1490578927-%7C1490578927
web_url("打开抽奖页面",
"URL=https://t.xxx.com/m/292.html",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t6.inf",
"Mode=HTML",
LAST );
return 0;
}