当前位置:   article > 正文

用模拟精灵写的自动投票系统_模拟精灵 for循环 里面 调用模拟区块

模拟精灵 for循环 里面 调用模拟区块

<?xml version="1.0" encoding="gb2312" ?>
<ApeML LID="CHS" MD="0" 抓屏模式="0" 名称="icctv-vote" 作者="xing006" 信息窗口="false" 速度="15" 循环次数="20" 自定义属性="ConnectionName = adsl,ConnectionPassword = m7x9b6r4,ConnectionUser = 100001230164">
 <!--创建时间:2005年11月30日-05:07-->
 <脚本区块 语言="LAScript" 名称="init" 延时="0" 启用="true" 编辑密钥="" 运行公钥="">
  <![CDATA[
_set = ape:loadSetting(); --读取自定义属性
stopPlay = function() --这个函数回放停止时被调用.
 ape:saveSetting(_set); --保存自定义属性
 collectgarbage();--清理内存
end;

import("net");
import("clean");

Forms=net.System.Windows.Forms
Drawing=net.System.Drawing

Form=Forms.Form
TextBox=Forms.TextBox
Label=Forms.Label
Button=Forms.Button
Point=Drawing.Point
Size=Drawing.Size
FormStartPosition=Forms.FormStartPosition
wb = web.new();

identify= function()
  
  clean.IE(false,true);
  local strUrl="http://"
  
  wb:setSilent(true,true);
  wb:go(strUrl);
  wb:show(false); 
  delay(200);
  
  for i=1,100,1 do      
   if(wb:getEle("CheckCode_input"))then
    local img=image.new();   
    img:getURL("http://","*.gif");
    
    if(img:ok())then
     img:corp(5,4,41,14);--对图进行修剪;
     local img2,img3,img4,img5=img:split(1,4);
     if(img2)then
      img2:median(2);--是否加中值滤波,及中值滤波的值,要根据实际情况进行调整。;
      img3:median(2);
      img4:median(2);
      img5:median(2);
     end;
  
     imgBinKey=bytestoImg();--得到包含样本图片的表
     local str="";--识别出来的文字
     str=test(imgBinKey,img2);
     str=str..test(imgBinKey,img3);
     str=str..test(imgBinKey,img4);
     str=str..test(imgBinKey,img5);   
     local ele=wb:getEle("CheckCode_input")
     ele:setAttribute("value",str);
     ele:submit();--提交表单
     image.del(img);
     image.del(img2);
     image.del(img3);
     image.del(img4);
     image.del(img5);
     element.del(ele);
     break;         
    end;
   end;
 
   if(i==100)then
    return false;
   end;
   delay(100)   
  end; 
  return true;
end;

function isConnect(url)

 local str = web.getURL(url);
 if (str=="")then 
  return false;
 end;

 if( string.find( str, "找不到服务器" ) )then
   return false;
 end;

 if( string.find( str , "没有可以显示的页面" ) )then
    return false;
 end;
 return true;
end;


function isConnectX()
 NETWORK_ALIVE_LAN  = 0x00000001 --是否有可用网卡
 NETWORK_ALIVE_WAN  = 0x00000002 -- 是否有可用远程连接
 NETWORK_ALIVE_AOL  = 0x00000004 -- NETWORK_ALIVE_AOL(仅对98/95有效判断是否联上美国的网络)

 --IsNetworkAlive的参数是传址的,所以需要用P来标记参数类型,然后在返回值中添加一个返回值flag
 IsNetworkAlive = dll.open("sensapi.dll", "IsNetworkAlive", "I(P)","stdcall")
 ok,flag = IsNetworkAlive(NETWORK_ALIVE_WAN); --ok对应上面的默认返回值I,flag对应上面的输出参数返回值P
 -- 注意上面的参数 ,应在网络连接以后延迟一下再检测是否有活动的连接

 if( ok == 0 )then
     return false;
 else
     if( (flag & NETWORK_ALIVE_WAN) == NETWORK_ALIVE_WAN)then
         return true;
     else
         return false;
     end;
 end;
end;

bytestoImg= function()
 local codeKey=ape:loadTable("验证码样本");--从数据岛读取表
 local imgBinKey={};--这个表是放真正的图像的
 
 toImage= function(k,v)
  local img9=image.new();
  img9:setBytes(string.decode(v,""),"*.gif");
  imgBinKey[k]=img9;
 end;
 
 table.foreach(codeKey,toImage)
 return imgBinKey;--调用函数,将返回包含样本图片的表
end;

test= function(imgBinKey,imgX)
 local limit=9999;
 local chr="";
 
 testImg= function(k,v)
  local n=imgX:testXX(imgBinKey[k]);
  if (n<limit) then
   limit=n;
   chr=k.."";
  end;
 end;
 
 table.foreach(imgBinKey,testImg);
 return chr
end; 

function dail(connN,connU,connP)
 collectgarbage();
 win.exec(win.getSysDir().."//rasdial.exe"," "..connName.." /DISCONNECT",win.getSysDir(),0);
 delay(2*1000); --延时2秒  
 win.exec(win.getSysDir().."//rasdial.exe"," "..connName.." "..connUser.." "..connPassword,win.getSysDir(),0);
 delay(5*1000); --延时2秒
end;


function btnVote_click(sender,args)
 


 connName = txtConnectionName.Text;
 connUser = txtConnectionUser.Text;
 connPassword = txtConnectionPassword.Text;
 
 ape:setRunNumber(txtVoteCount.Text);
 local i = 0;
 local j= ape:getRunNumber();
 while(i<j)
 do
  if(math.mod(i,10)==0)  then
   dail(connName,connUser,connPassword);
   if(isConnectX())then
       if(identify())then
     i=i+1
     lblValue.Text = i.."/"..j
     delay(1000);
    end;
   end;   
  else
   if(not isConnectX())then    
    dail(connName,connUser,connPassword);
   end;
   if(identify())then
    i = i + 1;
    lblValue.Text = i.."/"..j;
    delay(1000);
   end;
  end;  
 end;
end;


form = Form();
txtVoteCount = TextBox();
txtConnectionName = TextBox();
txtConnectionUser = TextBox();
txtConnectionPassword = TextBox();
lblVoteCount = Label();
lblConnectionName = Label();
lblConnectionUser = Label();
lblConnectionPassword = Label();
lblPercent = Label();
lblValue = Label();
btnVote = Button();
 
form:SuspendLayout();
 
lblVoteCount.Location = Point(10, 10);
lblVoteCount.Name = "lblVoteCount";
lblVoteCount.Size = Size(40, 10);
lblVoteCount.TabIndex = 0;
lblVoteCount.Text = "票数:";
 
txtVoteCount.Location = Point(80, 10);
txtVoteCount.Name = "txtVoteCount";
txtVoteCount.Size = Size(60, 60);
txtVoteCount.TabIndex = 1;
txtVoteCount.Text ="20000"
 
lblConnectionName.Location = Point(10, 40);
lblConnectionName.Name = "lblConnectionName";
lblConnectionName.Size = Size(70, 10);
lblConnectionName.TabIndex = 2;
lblConnectionName.Text = "拔号连接名:";
 
txtConnectionName.Location = Point(80, 40);
txtConnectionName.Name = "txtConnectionName";
txtConnectionName.Size = Size(60, 60);
txtConnectionName.TabIndex = 3;
txtConnectionName.Text ="adsl" 
 
lblConnectionUser.Location = Point(10, 70);
lblConnectionUser.Name = "lblConnectionUser";
lblConnectionUser.Size = Size(70, 10);
lblConnectionUser.TabIndex = 4;
lblConnectionUser.Text = "拔号用户名:";
 
txtConnectionUser.Location = Point(80, 70);
txtConnectionUser.Name = "txtConnectionUser";
txtConnectionUser.Size = Size(60, 60);
txtConnectionUser.TabIndex = 5;
txtConnectionUser.Text ="100001230164"
 
lblConnectionPassword.Location = Point(10, 100);
lblConnectionPassword.Name = "lblConnectionPassword";
lblConnectionPassword.Size = Size(70, 10);
lblConnectionPassword.TabIndex = 6;
lblConnectionPassword.Text = "拔号密码:";
 
txtConnectionPassword.Location = Point(80, 100);
txtConnectionPassword.Name = "txtConnectionPassword";
txtConnectionPassword.Size = Size(60, 60);
txtConnectionPassword.TabIndex = 7;
txtConnectionPassword.Text ="m7x9b6r4";

lblPercent.Location = Point(10, 130);
lblPercent.Name = "lblPercent";
lblPercent.Size = Size(70, 10);
lblPercent.TabIndex = 8;
lblPercent.Text = "进度:";

lblValue.Location = Point(80, 130);
lblValue.Name = "lblValue";
lblValue.Size = Size(70, 10);
lblValue.TabIndex = 9;
--lblValue.Text = "";
 
btnVote.Location = Point(70, 170);
btnVote.Name = "btnVote";
btnVote.TabIndex = 10;
btnVote.Text = "开始投票";
btnVote.Click:Add(btnVote_click);
 
form.AutoScaleBaseSize = Size(5, 13);
form.ClientSize = Size(200, 200);
form.Controls:Add(lblVoteCount);
form.Controls:Add(txtVoteCount);
form.Controls:Add(lblConnectionName);
form.Controls:Add(txtConnectionName);
form.Controls:Add(lblConnectionUser);
form.Controls:Add(txtConnectionUser);
form.Controls:Add(lblConnectionPassword);
form.Controls:Add(txtConnectionPassword);
form.Controls:Add(lblPercent);
form.Controls:Add(lblValue);
form.Controls:Add(btnVote);
form.Name = "MainForm"
form.Text = "ICCTV Vote"
form.StartPosition = FormStartPosition.CenterScreen
form.MaximizeBox=false;
form.MinimizeBox=true;
form:ResumeLayout(false);
form:ShowDialog();]]>
 </脚本区块>
 <数据区块>
  <验证码样本>
   <item key="0" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQWEMhApaX4Bj1tB5sXhtdEViZImqjnRgA7" ktype="string" vtype="string" />
   <item key="1" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQTEMgQpAW0Xpz31BsYehOJkZ1pRQA7" ktype="string" vtype="string" />
   <item key="2" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQXEIAQZrXXTsl3l9SnfWFHZVyZnuTpBhEAOw==" ktype="string" vtype="string" />
   <item key="3" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQUEIRJgb124qt3x9WWBWJWdihZXhEAOw==" ktype="string" vtype="string" />
   <item key="4" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQWEEgZwpzV3qyp7hWGfSFQZpeYUmsaAQA7" ktype="string" vtype="string" />
   <item key="5" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQVEIQAqpX30lxn35zHYeMmSqB3jkAEADs=" ktype="string" vtype="string" />
   <item key="6" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQWEIAQZpVUTn01915mcZ3YjWiaiaAXAQA7" ktype="string" vtype="string" />
   <item key="7" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQUMIA5g6T4YmA311S3iRn4mZ93ehEAOw==" ktype="string" vtype="string" />
   <item key="8" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQVEIAQZpVUWnw391/2jR02gpmorVIEADs=" ktype="string" vtype="string" />
   <item key="9" value="R0lGODlhCQAKAOMAAP///wAAAMjIyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAP8ALAAAAAAJAAoAAAQWEIAQZpVUWnwx19m3aWRHTiDYUezpRgA7" ktype="string" vtype="string" />
  </验证码样本>
 </数据区块>
</ApeML>

注意:需要dotnet1.1支持.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/488821
推荐阅读
相关标签
  

闽ICP备14008679号