Automatically submit form with WebBrower!

zhaozj2021-02-16  90

I often see how netizens on the network ask how to automatically submit forms, such as: How to log in to the forum, automatically log in to mailbox, and so on.

Today, I introduce a way I use - using WebBrower to submit.

Principle: Use the WebBrower controls that come with Delphi, display the page, then get the object DOCMENT, and use the program to analyze the FORM architecture, fill in the data.

Below, we will do a simplest automatic submission process.

Development steps:

Step1: New project

Step2: Play the control webbrower on the form, put a Button button.

Step3: Write the following code in the oncreate event in the form: WebBrowser1.naviGate ('You want to submit the page address');

Step4: The onclick event of Button1 is written as follows

Var myitem: olevariant; i: integer; begin

MyItem: = WebBrowser1.document; for i: = 0 to myitem.all.length - 1 do begin if myitem.all.item (i) .tagname = 'select' the// drop-down box Select Begin //MyItem.all. Item (i) .value: = '2'; // Select the second item from the drop-down box;

IF myitem.all.Item (i) .tagname = 'input' Then Begin if Uppercase (MyItem.all.Item (i) .type) = 'Radio' Then Begin if myitem.all.Item (i) .value = ' Node 'Then MyItem.all.item (i) .checked: = true; // Select the value end;

IF Uppercase (MyItem.all.Item (i) .Type) = 'Text' Then Begin if Uppercase (MyItem.all.Item (i) .Name) = 'Username' Then MyItem.all.Item (i) .value: = 'lovefox'; if Uppercase (MyItem.all.Item (i) .Name) = 'Subject' Then MyItem.all.Item (i) .value: = 'Your Theme';

END;

If Uppercase (MyItem.all.item (i) .type) = 'password' Then Begin if Uppercase (MyItem.all.Item (i) .Name) = 'password' Ten MyItem.all.item (i) .value: = 'abcd123'; end;

IF Uppercase (MyItem.all.item (i). ^ = 'Ten Begin if Uppercase (MyItem.all.Item (i) .Name) =' Topicsubmit 'Ten MyItem.all.item (i) .click; // Click the submission key END;

End; // Tagname = Inputif myitem.all.item (i) .tagname = 'textarea' TEN // Multi-line text Begin if Uppercase (MyItem.all.item (i) .Name) = 'Message' Ten MyItem.all .Item (i) .value: = 'body content';

End; // for i end;

Step5: Compile operation.

Description: TAGNAME Attributes Type of Page Elements, common INPUT, TextArea, SELECT, SUBMIT, etc. Finally, the Value property is assigned to the specified page element.

Mastering these, you can use it flexibly, such as the page address to be accessed with the INI file and the type name of the element to be submitted, so that by configuration, you can access different sites, complete the article, such as the forum, automatically publish articles, automatically log in to the web Mail page, etc.

Disadvantages: Webbrwoer wants to display the page before you can submit, slower speed, no need to view as long as you submit data, it looks not simple enough. In addition, when multiple forums are submitted to an article, they should log in to several different websites and are not reasonable. Hope, the master can point to the data using the Socket method to submit the data. Finally, the page that has an additional code can be logged in, and it is not a heart. I hope the master can continue.

转载请注明原文地址:https://www.9cbs.com/read-11878.html

New Post(0)