HanDs
管理员

[Delphi文章] delphi 对网页自动操作 



uses mshtml,IdHTTP;
 
procedure TFrmmain.Act_BeginWrite;
var
  myitem:Olevariant;
  i:integer;
  tmp:string;
  TemName:String;
  TemIniFile:TIniFile;
begin

 Try
    myitem := WebBrowser1.Document;

    for i := 0 to myitem.all.length - 1 do
    begin
      if myitem.all.item(i).tagName = 'INPUT' then
      begin
        if Uppercase(myitem.all.item(i).type)='TEXT' then //文本框
        begin

          TemName:=Act_GetName+RANDOMStr(1);

          if Uppercase(myitem.all.item(i).name)='USERNAME' then
          begin
            myitem.all.item(i).focus;
            myitem.all.item(i).value:=TemName;
            TemIniFile:=TIniFile.Create(ExtractFilePath(ParamStr(0))+'name.ini');
            TemIniFile.WriteString(FormatDateTime('YYYY-MM-DD HH:mm:ss',now),'Name',TemName);
            TemIniFile.Free;
          end;
        end;
      end;
    end;


     keybd_event(VK_SPACE,MapVirtualKey(VK_SPACE,0),0,0);

     keybd_event(VK_SPACE,MapVirtualKey(VK_SPACE,0),KEYEVENTF_KEYUP,0);

     keybd_event(VK_TAB,MapVirtualKey(VK_TAB,0),0,0);

     keybd_event(VK_TAB,MapVirtualKey(VK_TAB,0),KEYEVENTF_KEYUP,0);


    for i := 0 to myitem.all.length - 1 do
    begin
      if myitem.all.item(i).tagName = 'INPUT' then
      begin
        IF Uppercase(myitem.all.item(i).type)='RADIO' then //选择一个
        begin
           If Uppercase(myitem.all.item(i).name)='RADIOBUTTON' then
           begin
             myitem.all.item(i).checked :=true;

               if FYX_GetRanDom(1)= 1 then
                 break;
           end;
        end;
      end;
    end;


    for i := 0 to myitem.all.length - 1 do
    begin
      if   myitem.all.item(i).tagName = 'SELECT' then
      begin
        if Uppercase(myitem.all.item(i).id)='DRPPID' then //文本框
        begin
          if Uppercase(myitem.all.item(i).name)='DRPPID' then
          begin
            if myitem.all.item(i).tagName = 'OPTION' then
              myitem.all.item(i).selected:='SELECTED';
          end;
        end;
      end;
    end;

      sleep(1000);

    for i:= 0 to myitem.all.length - 1 do
    begin
      if myitem.all.item(i).tagName = 'INPUT' then
      begin
        if Uppercase(myitem.all.item(i).type)='TEXT' then //文本框
        begin

          If Uppercase(myitem.all.item(i).name)='USERNICK' then
          begin

            myitem.all.item(i).value:=Act_GetName;

          end;
        end;
      end;
    end;


    for i:=0 to myitem.all.length - 1 do
    begin
      if myitem.all.item(i).tagName = 'INPUT' then
      begin
        if Uppercase(myitem.all.item(i).type)='TEXT' then //文本框
        begin
          If Uppercase(myitem.all.item(i).name)='TXTCHECKNUM' then
             myitem.all.item(i).value:=FYX_GetCodeID;
        end;
      end;
    end;

    for i:=0 to myitem.all.length - 1 do
    begin
     if myitem.all.item(i).tagName = 'INPUT' then
      begin
        IF Uppercase(myitem.all.item(i).type)='PASSWORD' then //文本框
        begin
          If Uppercase(myitem.all.item(i).name)='PASSWORD1' then
             myitem.all.item(i).value:=1234567;

        end;
      end;
    end;


    for i := 0 to myitem.all.length - 1 do
    begin
     if myitem.all.item(i).tagName = 'INPUT' then
      begin
        IF Uppercase(myitem.all.item(i).type)='PASSWORD' then //文本框
        begin

          If Uppercase(myitem.all.item(i).name)='PASSWORD_CNF' then
             myitem.all.item(i).value:=1234567;
        end;
      end;
    end;


    ((WebBrowser1.Document   as   IHTMLDocument2).all.item('selYear',   0)   as
            IHTMLSelectElement).selectedIndex   := FYX_GetRanDomYear(35);

    ((WebBrowser1.Document   as   IHTMLDocument2).all.item('selMonth',   0)   as
         IHTMLSelectElement).selectedIndex   :=  FYX_GetRanDom(13);

    ((WebBrowser1.Document   as   IHTMLDocument2).all.item('selDay',   0)   as
             IHTMLSelectElement).selectedIndex   :=  FYX_GetRanDom(30);

     ((WebBrowser1.Document   as   IHTMLDocument2).all.item('drpPid',   0)   as
            IHTMLSelectElement).selectedIndex   :=  FYX_GetRanDom(30);


    tmp := 'GetCity(''drpPid'',''drpCity'')';
    WebBrowser1.OleObject.Document.parentWindow.execScript(tmp,'JavaScript');

   ((WebBrowser1.Document   as   IHTMLDocument2).all.item('drpCity',   0)   as
            IHTMLSelectElement).selectedIndex   :=  FYX_GetRanDom(5)-1;


   for i := 0 to myitem.all.length - 1 do
   begin
     if myitem.all.item(i).tagName = 'INPUT' then
     begin
       if  Uppercase(myitem.all.item(i).type)='CHECKBOX' then  //Checkbox
       begin
         If Uppercase(myitem.all.item(i).name)='CHKAGREEMENT' then
           myitem.all.item(i).checked :=true;
       end;
     end;
   end;

     //showmessage('OK');

   for i := 0 to myitem.all.length - 1 do
   begin
     if myitem.all.item(i).tagName = 'INPUT' then
     begin
       if Uppercase(myitem.all.item(i).type)='SUBMIT' then //找按钮点击
       begin
         myitem.all.item(i).click;
       end;
     end;
   end; //Tagname = Input

  Except
  end;         


  TemNum:=TemNum-1;
  EdNum.Text:=IntToStr(TemNum);

  SumNum:=SumNum+1;

 

  if TemNum <= 0 then
    Close;
 
  Timer4.Enabled:=True;
end;

 


学习中请遵守法律法规,本网站内容均来自于互联网,本网站不负担法律责任
delphi 对网页自动操作
#1楼
发帖时间:2016-7-9   |   查看数:0   |   回复数:0
游客组
快速回复