首页 > 代码库 > LRODRUNNER关联拼接飞机票

LRODRUNNER关联拼接飞机票

web_url("Search Flights Button", 
        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search", 
        "TargetFrame=body", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", 
        "Snapshot=t16.inf", 
        "Mode=HTML", 
        LAST);

    lr_think_time(21);

    web_submit_data("reservations.pl", 
        "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome", 
        "Snapshot=t17.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=advanceDiscount", "Value=http://www.mamicode.com/0", ENDITEM, 
        "Name=depart", "Value=http://www.mamicode.com/London", ENDITEM, 
        "Name=departDate", "Value=http://www.mamicode.com/02/24/2017", ENDITEM, 
        "Name=arrive", "Value=http://www.mamicode.com/San Francisco", ENDITEM, 
        "Name=returnDate", "Value=http://www.mamicode.com/02/25/2017", ENDITEM, 
        "Name=numPassengers", "Value=http://www.mamicode.com/2", ENDITEM, 
        "Name=seatPref", "Value=http://www.mamicode.com/Aisle", ENDITEM, 
        "Name=seatType", "Value=http://www.mamicode.com/First", ENDITEM, 
        "Name=.cgifields", "Value=http://www.mamicode.com/roundtrip", ENDITEM, 
        "Name=.cgifields", "Value=http://www.mamicode.com/seatType", ENDITEM, 
        "Name=.cgifields", "Value=http://www.mamicode.com/seatPref", ENDITEM, 
        "Name=findFlights.x", "Value=http://www.mamicode.com/65", ENDITEM, 
        "Name=findFlights.y", "Value=http://www.mamicode.com/7", ENDITEM, 
        LAST);

    web_submit_data("reservations.pl_2", 
        "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Snapshot=t18.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=outboundFlight", "Value=http://www.mamicode.com/260;1099;02/24/2017", ENDITEM, 
        "Name=numPassengers", "Value=http://www.mamicode.com/2", ENDITEM, 
        "Name=advanceDiscount", "Value=http://www.mamicode.com/0", ENDITEM, 
        "Name=seatType", "Value=http://www.mamicode.com/First", ENDITEM, 
        "Name=seatPref", "Value=http://www.mamicode.com/Aisle", ENDITEM, 
        "Name=reserveFlights.x", "Value=http://www.mamicode.com/66", ENDITEM, 
        "Name=reserveFlights.y", "Value=http://www.mamicode.com/15", ENDITEM, 
        LAST);

    lr_think_time(9);

    web_submit_data("reservations.pl_3", 
        "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Snapshot=t19.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=firstName", "Value=http://www.mamicode.com/Joseph", ENDITEM, 
        "Name=lastName", "Value=http://www.mamicode.com/Marshall", ENDITEM, 
        "Name=address1", "Value=http://www.mamicode.com/234 Willow Drive", ENDITEM, 
        "Name=address2", "Value=http://www.mamicode.com/San Jose/CA/94085", ENDITEM, 
        "Name=pass1", "Value=http://www.mamicode.com/Joseph Marshall", ENDITEM, 
        "Name=pass2", "Value=http://www.mamicode.com/", ENDITEM, 
        "Name=creditCard", "Value=http://www.mamicode.com/123456", ENDITEM, 
        "Name=expDate", "Value=http://www.mamicode.com/0223", ENDITEM, 
        "Name=oldCCOption", "Value=http://www.mamicode.com/", ENDITEM, 
        "Name=numPassengers", "Value=http://www.mamicode.com/2", ENDITEM, 
        "Name=seatType", "Value=http://www.mamicode.com/First", ENDITEM, 
        "Name=seatPref", "Value=http://www.mamicode.com/Aisle", ENDITEM, 
        "Name=outboundFlight", "Value=http://www.mamicode.com/260;1099;02/24/2017", ENDITEM, 
        "Name=advanceDiscount", "Value=http://www.mamicode.com/0", ENDITEM, 
        "Name=returnFlight", "Value=http://www.mamicode.com/", ENDITEM, 
        "Name=JSFormSubmit", "Value=http://www.mamicode.com/off", ENDITEM, 
        "Name=.cgifields", "Value=http://www.mamicode.com/saveCC", ENDITEM, 
        "Name=buyFlights.x", "Value=http://www.mamicode.com/39", ENDITEM, 
        "Name=buyFlights.y", "Value=http://www.mamicode.com/10", ENDITEM, 
        LAST);

    web_submit_data("reservations.pl_4", 
        "Action=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl", 
        "Snapshot=t20.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=Book Another.x", "Value=http://www.mamicode.com/57", ENDITEM, 
        "Name=Book Another.y", "Value=http://www.mamicode.com/17", ENDITEM, 
        LAST);

    web_url("SignOff Button", 
        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", 
        "TargetFrame=body", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights", 
        "Snapshot=t21.inf", 
        "Mode=HTML", 
        LAST);

    return 0;
}

黄色部分正好是选择出发城市和目的城市之后的页面出现的四种机票之一,要想在脚本回放的过程中,无论前一页选择了什么出发城市和目的城市,然后在这一页都能随机的选择一种机票所以此处黄色部分可以先关联出来,然后直接用参数替代,就可以达到想要的效果了

技术分享

 

 服务器应答内容:

<center>
<!-- From London (2) To San Francisco (6) -->
<table cellspacing=2 border=0 width=50%>
<blockquote>Flight departing from <B>London</B> to <B>San Francisco</B> on <B>02/24/2017</B><BR><BR>
<tr bgcolor=#5E7884><td align=center><font color=white><B>Flight</B></font>
              <td align=center><font color=white><B>Departure time</B>
              <td align=center><font color=white><B>Cost</B>
<tr bgcolor=#EFF2F7><td align=center><input type = radio name=outboundFlight value=http://www.mamicode.com/260;1099;02/24/2017
 checked >Blue Sky Air 260<td align=center>8am<td align=center>$ 1099</TD></TR><tr bgcolor=#EFF2F7><td
 align=center><input type = radio name=outboundFlight value=http://www.mamicode.com/261;979;02/24/2017>Blue Sky Air 261<td align
=center>1pm<td align=center>$ 979</TD></TR><tr bgcolor=#EFF2F7><td align=center><input type = radio name
=outboundFlight value=http://www.mamicode.com/262;1039;02/24/2017>Blue Sky Air 262<td align=center>5pm<td align=center>$ 1039
</TD></TR><tr bgcolor=#EFF2F7><td align=center><input type = radio name=outboundFlight value=http://www.mamicode.com/263;899
;02/24/2017>Blue Sky Air 263<td align=center>11pm<td align=center>$ 899</TD></TR></table>
//拆分一下页面4种选择
name=outboundFlight value=http://www.mamicode.com/260;1099;02/24/2017checked >Blue Sky Air 260<td
name=outboundFlight value=http://www.mamicode.com/261;979;02/24/2017>Blue Sky Air 261<td
name=outboundFlight value=http://www.mamicode.com/262;1039;02/24/2017>Blue Sky Air 262<td
name=outboundFlight value=http://www.mamicode.com/263;899;02/24/2017>Blue Sky Air 263<td align=center>11pm<td

根据多次出发城市和到达城市匹配  每次页面都会有1个这样的值name=outboundFlight value=http://www.mamicode.com/260;1099;02/24/2017checked >Blue Sky Air 260

需要关联动态值:260;1099;02/24/2017

确定左右边界值, 这里我把左边界设置outboundFlight value= http://www.mamicode.com/右边界2017、然后再最下面{Flight}2017直接拼接就可以用了

web_reg_save_param("Flight",
"LB=name=outboundFlight value=http://www.mamicode.com/",
"RB=2017",
// "Ord=3",
LAST);//关联服务器根据每次选择的出发城市与目标城市动态航班次机以及机票价格

 

关联成功后  运行结果如下:

Action.c(101): 100;386;02/21/  //航班班次 票价 出发日期
Action.c(102): Frankfurt,Denver  //出发城市 到底城市
Action.c(101): 210;266;02/21/
Action.c(102): London,Frankfurt
Action.c(101): 320;773;02/21/
Action.c(102): Los Angeles,London
Action.c(101): 430;438;02/21/
Action.c(102): Paris,Los Angeles
Action.c(101): 540;621;02/21/
Action.c(102): Portland,Paris

 

LRODRUNNER关联拼接飞机票