百度腾讯QQ等网站注册自动提交表单源码2012最新

来源:互联网 发布:电影百万杀人游戏 知乎 编辑:程序博客网 时间:2024/05/17 09:31

闲的无聊的时候研究了下delphi网络模块。就简单模仿了下自动注册或者登陆网站这么一个功能来练手。闲话不多讲,代码奉上~

以下是腾讯QQ的填写表单和自动提交代码,直供研究学习使用,不得用于其他用途啊~~

先讲一下大致流程吧,要想自动提交表单,那么就需要知道网页中的各个元素,比如昵称输入框,生日选择框,表单提交按钮。对于这些元素可以使用网页源码查看来取得,然后就是使用控件取得这些元素,对这些元素进行操作。

在研究腾讯的QQ注册的时候出现过不少问题,到目前为止解决的问题有

1.QQ注册生日下拉框的赋值问题,因为它的类型不是下拉框也不是其他类型,腾讯这里设计的比较高级,我变化方法来取值的。

2.focus焦点问题。因为表单提交的时候需要onclick事件,在这个事件中需要验证提交的数据是否合法,之前想采用tab键自动按键的发现没有效果,最后使用的是onfocus来获得焦点,使其自动验证。

3.表单提交的问题。获得表单按钮的问题,这个问题也得到了解决。

目前还存在的问题:

1.验证码正确显示问题。现在腾讯的验证码比较高级,其验证码的源码显示的图片不是固定的,没有研究明白~百度的就可以正确获得,但是腾讯的~~头疼Ing

2.表单提交问题,需要点击两次提交。。不知道第一次为啥不起作用。只能分开一个填表按钮一个提交按钮。都放在一个事件中不成功。。

3.还有未完善的地方。自动申请的还没写保存事件。。。还有一些bug

好吧。献丑了,一些代码~~

procedure TMainFrm.FillAtecentForm;var //自动填充表单Doc: IHTMLDocument2;input_nickElement, input_PwdElement,input_rePwdElement, input_ValideCodeElement, input_YearElement,input_monthElement, input_DayElement, input_submit: IHTMLInputElement;begin   doc := WebBrowser.document as ihtmldocument2;   input_nickElement := (doc.all.item('nick',0) as IHTMLInputElement);   input_nickElement.value := '注册一个';   WebBrowser.OleObject.Document.getElementByID('nick').focus();   input_PwdElement := (doc.all.item('password',0) as IHTMLInputElement);   input_PwdElement.value := PassWordString;   WebBrowser.OleObject.Document.getElementByID('password').focus();   input_rePwdElement := (doc.all.item('pass_again',0) as IHTMLInputElement);   input_rePwdElement.value := PassWordString;   WebBrowser.OleObject.Document.getElementByID('pass_again').focus();   input_YearElement := (doc.all.item('year_value',0) as IHTMLInputElement);   input_YearElement.value := '1991年';   WebBrowser.OleObject.Document.getElementByID('year_value').focus();   input_monthElement := (doc.all.item('month_value',0) as IHTMLInputElement);   input_monthElement.value := '2月';   WebBrowser.OleObject.Document.getElementByID('month_value').focus();   input_DayElement := (doc.all.item('day_value',0) as IHTMLInputElement);   input_DayElement.value := '1日';   WebBrowser.OleObject.Document.getElementByID('day_value').focus();   input_ValideCodeElement := (doc.all.item('code',0) as ihtmlinputelement);   if input_ValideCodeElement.status then   begin     input_ValideCodeElement.value := Trim(Edit1.Text);     WebBrowser.OleObject.Document.getElementByID('code').focus();   end;   input_submit := (doc.all.item('submit',0) as ihtmlinputelement);   WebBrowser.OleObject.Document.getElementByID('submit').focus();end;

表单提交的。

procedure TMainFrm.btn2Click(Sender: TObject);var  input : OleVariant;  Doc : IHTMLDocument2;begin  //自动提交表单  doc := WebBrowser.document as ihtmldocument2;  input := doc.all.item('submit',0);  input.click;end;


下面是百度的,随机的邮箱嘿嘿。仅供学习使用~

procedure TMainFrm.RegistABaiduAcount;varDoc :IHTMLDocument2;input_EmailElement, input_userNameElement, input_PwdElement,input_rePwdElement, input_ValideCodeElement, input_submit: IHTMLInputElement;ArandomInt, I : Integer;SourceStr,Str:String;begin   Str := '';   SourceStr:='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';   Randomize;   for I := 0 to 4 do     Str := Str + SourceStr[Random(51)];   Randomize;   ArandomInt := Random(999999999);   Str := Str + IntToStr(ArandomInt);   input_EmailElement :=(doc.all.item('email',0) as ihtmlinputelement);   input_EmailElement.value:= IntToStr(ArandomInt)+ '@qq.com';   input_userNameElement :=(doc.all.item('username',0) as ihtmlinputelement);   input_userNameElement.value := Str;   input_PwdElement :=(doc.all.item('loginpass',0) as ihtmlinputelement);   input_PwdElement.value:= PassWordString;   input_rePwdElement :=(doc.all.item('verifypass',0) as ihtmlinputelement);   input_rePwdElement.value:= PassWordString;   input_ValideCodeElement := (doc.all.item('verifycode',0) as ihtmlinputelement);   input_ValideCodeElement.value := Edit1.Text;   input_submit.select;   WebBrowser.oleobject.document.Forms.Item(0 , 0).submit;//   BaiDuWebBrowser.Refresh2;//   ShowValideCodeImage;end;

好了。。还有一些没做好的地方,大家可以帮忙看下能不能弄好~~一起交流啊。。欢迎大家留言。。源码在完善后会整个贴出~~目前想要的可以单独跟我要~