/**********************
* 好了,运行这段脚本完成文件下载并写到本地的操作
* 如果我们需要重复保存这个文件到本地,如何解决重名问题呢,下面这段代码可以随机生成文件名
*
*
* char file[256]="\0";
* char * chNumber
* chNumber=lr_eval_string("{Random}"); //生成随机数
*
* strcat(file,"c:\\test");
* strcat(file,chNumber);
* strcat(file,".rar");
*
*
************/
Action()
{
int flen; //定义一个整型变量保存获得文件的大小
long filedes; //保存文件句柄
char file[256]="\0"; //保存文件路径及文件名
char * chNumber;
chNumber=lr_eval_string("{Random}"); //生成随机数
web_set_max_html_param_len("2000000");//设置页面接收最大的字节数,该设置应大于下载文件的大小
web_set_proxy ("127.0.0.1:8888");
lr_start_transaction("getMenuDatashtml");
//点击小房子
web_url("EosMenuAction!getMenuData.shtml",
"URL=http://10.1.30.159:7013/aml/sysManage/EosMenuAction!getMenuData.shtml?_=1530072991152&alllifesessionid=0dca48cf-d4ff-41d5-b026-943beae2743b&jsonpcallback=jsonp1530072965162",
"TargetFrame=",
"Resource=1",
"RecContentType=application/json",
"Referer=http://10.1.30.159/portal/runtime/uiservice/menuTreeUIService.jsp",
"Snapshot=t27.inf",
LAST);
lr_end_transaction("getMenuDatashtml", LR_AUTO);
lr_start_transaction("downloadfileList_03");
//<a href="/aml/reportfilemanage/ReportFile_downloadfile.shtml?repfile.pkid=50938">下载 </a>
//关联下载文件的pkid,文件序号
web_reg_save_param("file_content",
"LB=ReportFile_downloadfile.shtml?repfile.pkid=",
"RB=\">",
LAST);
//点击查询数据包状态已下载上报的
web_submit_data("ReportFile_downloadfileList.shtml",
"Action=http://10.1.30.159:7013/aml/reportfilemanage/ReportFile_downloadfileList.shtml",
"Method=POST",
"TargetFrame=listFrame",
"RecContentType=text/html",
"Referer=http://10.1.30.159:7013/aml/reportfilemanage/ReportFile_enterModelCondition.shtml?to=downloadfile",
"Snapshot=t33.inf",
"Mode=HTML",
ITEMDATA,
"Name=repcon.repStatus", "Value=5", ENDITEM,
"Name=repcon.startDate", "Value=", ENDITEM,
"Name=reppackagefile.pkgType", "Value=", ENDITEM,
"Name=reppackagefile.repType", "Value=", ENDITEM,
"Name=repcon.endDate", "Value=", ENDITEM,
"Name=reppackagefile.status", "Value=p02", ENDITEM,
"Name=reppackagefile.trantDate", "Value=", ENDITEM,
EXTRARES,
"Url=ReportFile_downloadfile.shtml?repfile.pkid={file_content}", ENDITEM,
LAST);
lr_end_transaction("downloadfileList_03",LR_AUTO);
//关联服务器全部下载返回的内容
web_reg_save_param("filecontent",
"LB=",
"RB=",
"Search=ALL",
LAST);
//关联服务器响应的头文件中获取下载文件名
web_reg_save_param("file","LB=filename=","RB=\r","Search=ALL",LAST);
lr_start_transaction("download_04");
web_url("下载",
"URL=http://10.1.30.159:7013/aml/reportfilemanage/ReportFile_downloadfile.shtml?repfile.pkid={file_content}",
"TargetFrame=",
"Resource=0",
"RecContentType=application/x-download",
"Referer=http://10.1.30.159:7013/aml/reportfilemanage/ReportFile_downloadfileList.shtml",
"Snapshot=t34.inf",
"Mode=HTML",
LAST);
lr_end_transaction("download_04",LR_AUTO);
strcat(file,"C:\\test\\"); //将“c:\\”这个路径保存到file中
strcat(file,lr_eval_string("{file}"));//将获得的文件名拼接在file这个变量字符串之后
flen = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE); //获得文件返回大小
if(flen > 0)
{
if((filedes = fopen(file, "wb")) == NULL)
{
lr_output_message("Open File Failed!", lr_eval_string("{filecontent}"));
return -1;
}
fwrite( lr_eval_string("{filecontent}"),flen,1,filedes );
fclose( filedes );
}
return 0;
}
原文:https://www.cnblogs.com/Alexr/p/9360703.html