花褪残红青杏小。燕子飞时,绿水人家绕。

delphi实现自动填写表单和调用网页上的函数

菜鸟编程 十五楼的鸟儿 21202浏览 0评论

纯属无聊,搞这么个dd,表乱传哈~

var
  Doc : IHTMLDocument2;
  input: OleVariant;
  userinputelement , pwdinputelement : ihtmlinputelement;

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption:='';
  datex:= FormatDateTime('yyyymmddhhnnss',now());
  nicheng:=FormatDateTime('mmddhhnnss',now());
    doc:=webbrowser1.document as ihtmldocument2;
    userinputelement:=(doc.all.item('email',0) as ihtmlinputelement);
    zhanghao:=datex;
    userinputelement.value:=zhanghao+'@163.com';
    pwdinputelement:=(doc.all.item('nickname',0) as ihtmlinputelement);
    pwdinputelement.value:='昵称'+nicheng;
    pwdinputelement:=(doc.all.item('password',0) as ihtmlinputelement);
    pwdinputelement.value:='1111';
    pwdinputelement:=(doc.all.item('repassword',0) as ihtmlinputelement);
    pwdinputelement.value:='1111';
    pwdinputelement:=(doc.all.item('authCode',0) as ihtmlinputelement);
    pwdinputelement.value:=Edit2.Text;
    input:=doc.all.item('div_Reg',0);
    input.click;
    Memo1.Lines.Add(zhanghao);
     repeat
     Application.ProcessMessages ;
     until(not webbrowser1.Busy);
     Sleep(1000);//貌似not busy的判断不是很准,所以sleep之后再判断一次,出错次数减少了,但是偶尔还会出错,建议网速慢的,就多sleep一会,嘿嘿~ 1000的单位是ms(毫秒)
     repeat
     Application.ProcessMessages ;
     until(not webbrowser1.Busy);

    Form1.Button2.click();


end;

procedure TForm1.Button2Click(Sender: TObject);
begin
try
 WebBrowser1.OleObject.document.parentWindow.ChannelList.QuickAppend.OpenPannel();
//网页上的函数为 onclick="ChannelList.QuickAppend.OpenPannel()"
   doc2:=webbrowser1.document as ihtmldocument2;
   userinputelement:=(doc.all.item('quickFeedInput',0) as ihtmlinputelement);
   userinputelement.value:=feedrss;
    input:=doc2.all.item('quickAppend',0);
    input.click;
     repeat
     Application.ProcessMessages ;
     until(not webbrowser1.Busy);
     Sleep(1000);
     repeat
     Application.ProcessMessages ;
     until(not webbrowser1.Busy);
     Form1.Button3.click();
except
Label1.Caption:='出错';
end;end;[/code]
[code=delphi]
//如果提交按钮没有name属性
var
  formx:IHTMLFormElement;
    formx:=(doc.all.item('regist',0) as ihtmlformelement);
    formx.submit;
[/code]
[code=delphi]
//使用字典
Randomize;
 i:=Random(9999);
  List := TStringList.Create;
  List.LoadFromFile('456zidian.txt');
  S:= List[i];


如果表单中包含有select下拉列表,一般为密码保护问题等等。

  input:=WebBrowser1.OleObject.Document.all.Item('question',0);
   input.value:='我最喜欢的运动员是谁?';//此处即为select下拉列表中的任意一个value。

附上一个延时函数,不再需要sleep

{在使用之前声明即可}
procedure Delay(MSecs: Longint);
//延时函数,MSecs单位为毫秒(千分之1秒)
var
FirstTickCount, Now: Longint;
begin
FirstTickCount := GetTickCount();
repeat
    Application.ProcessMessages;
    Now := GetTickCount();
until (Now - FirstTickCount >= MSecs) or (Now < FirstTickCount);
end;

一个函数,判断字符串中是否包含,可以根据这个判断返回的url是否是表单成功提交的url

//s:='cyh9519'
 //pos('y',s)>0
 //pos函数返回‘y’在S中的位置,如果是0就说明不包含


转载请注明:鸟儿博客 » delphi实现自动填写表单和调用网页上的函数

游客
发表我的评论 换个身份
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址