/*select province*/
lr_start_transaction("Defaultpage");
web_url("Province",
"URL=http://m.weathercn.com/province.jsp",
"Resource=0",
"RecContentType=text/html",
"Referer=http://m.weathercn.com/?cid=01012601",
"Snapshot=t2.inf",
"Mode=HTTP",
LAST);
lr_end_transaction("Defaultpage",LR_AUTO);
lr_paramarr_len("ProvincesCode"); /*'输出数组长度'*/
/*save random procince code as a parameter*/
sprintf(ProvinceCode,"%s",lr_paramarr_random("ProvincesCode"));
/*根据数组内容来随机获取并保存为变量*/
lr_save_string(lr_eval_string(ProvinceCode),"ProvinceCode");
/*将变量保存为参数,这一步是必需的,否则将无法参数化*/
lr_output_message("%s",lr_eval_string("{ProvinceCode}"));
/*obtain city code,web_reg_save_param can function well here, but not suggest
ed */
web_reg_save_param(
"CitiesCode",
"LB=did=",
"RB=&pid=",
"ORD=all",
LAST);
/*select city */
lr_start_transaction("SelectCity");
web_url("City",
"URL=http://m.weathercn.com/dis.do?pid={ProvinceCode}",
/* the default value is 0101114*/
"Resource=0",
"RecContentType=text/html",
"Referer=http://m.weathercn.com/province.jsp",
"Snapshot=t3.inf",
"Mode=HTTP",
LAST);
lr_end_transaction("SelectCity",LR_AUTO);
/* save city code as a parameter*/
sprintf(CityCode,"%s",lr_paramarr_random("CitiesCode"));
lr_save_string(lr_eval_string(CityCode),"CityCode");
lr_output_message("%s",lr_eval_string("{CityCode}"));
/*obtain district code*/
web_reg_save_param(
"DistrictsCode",
"LB=cid=",
"RB=&pid",
"ORD=all",
LAST);
/*obtain district name for text check.*/
web_reg_save_param_regexp(
"paramName=DistrictsName",
"RegExp=class=\"c\">(.{4,8})\r\n",
/*match Chinese character use ([\u4e00-\u9fa5]{4,6}).. because chinese
character display inproper here */
"Ordinal=all",
LAST);
.
.
.
.
.
.
.
'中间太长了我就不贴了,操作都是类似的。下面通过是将具体的省、市、区保存为参数来进行参数化'
/* generate random number to acquire a district name corresponding with district code*/
srand(time(NULL));
DistrictSequence=(rand()%(lr_paramarr_len("DistrictsCode")))+1;
/*save district name and district code as a parameter*/
lr_output_message("%d",DistrictSequence);
sprintf(DistrictName,"{DistrictsName_%d}",DistrictSequence);
lr_save_string(lr_eval_string(DistrictName),"DistrictName");
sprintf(DistrictCode,"{DistrictsCode_%d}",DistrictSequence);
lr_save_string(lr_eval_string(DistrictCode),"DistrictCode");
lr_output_message("%s",lr_eval_string("{DistrictName}"));
lr_output_message("%s",lr_eval_string("{DistrictCode}"));
/*text check*/
/*设置文本检查点,下好从上面保存为参数的DistrictName中获取*/
web_reg_find("Search=Body",
"Text={DistrictName}",
LAST);
/*weather report*/
lr_start_transaction("ReportPage");
web_url("WeatherReport",
"URL=http://m.weathercn.com/index.do?cid={DistrictCode}&pid={ProvinceCode}", /* default cid=0101141012 pid=0101114*/
"Resource=0",
"RecContentType=text/html",
"Referer=http://m.weathercn.com/cout.do?did={CityCode}&pid={ProvinceCode}",
"Snapshot=t5.inf",
"Mode=HTTP",
LAST);
lr_end_transaction("ReportPage",LR_AUTO);
/*以下内容没有进行参数化,以下内容主要是一些像显示天气状态的图片内容,之前看到过一篇文件说关于web_concurrent_start只是提交的数据有区别,所以没有必要进行参数化' */
/* you can parameterize the following value */
web_concurrent_start(NULL);
web_url("Day02.png",
"URL=http://m.weathercn.com/fh30/Day02.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://m.weathercn.com/index.do?cid=0101141012&pid=010114",
LAST);
web_url("Day00.png",
"URL=http://m.weathercn.com/fh100/Day00.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://m.weathercn.com/index.do?cid=0101141012&pid=010114",
LAST);
web_url("Night02.png",
"URL=http://m.weathercn.com/fh30/Night02.png",
"Resource=1",
"RecContentType=image/png",
"Referer=http://m.weathercn.com/index.do?cid=0101141012&pid=
010114",
LAST);
web_concurrent_end(NULL);
return 0;
}
/*这里有一点疑问,之前看自动关联LR生成的关联中写的为RegExp=pid=(.*?)\ \\" class,一直
没有弄明白,这里为什么会多出一个\\而仍然可以关联成功
关联以获取到所有的省代码,LR在C语言中并不推荐使用web_reg_save_param_ex函数,这里用其
实也是可以通过的下面我们就来简单的看一个服务器返回的内容来如何进行参数化。*/
web_reg_save_param_regexp(
"paramName=DistrictsName",
"RegExp=class=\"c\">(.{4,8})\r\n", /*match Chinese character use ([\u4e00-\u9fa5]{4,6}).. because chinese character display inproper here */
"Ordinal=all",
LAST);
/* '这里通过限制长度还是能够正确获取的'*/