Using VB to implement automatic mailbox registration (i): Form automatic submission

Source: Internet
Author: User
Tags implement integer trim
A few days ago on the internet to see someone need a mailbox automatic registration procedures, so I also wrote a, in the process of checking the data I saw some netizens wrote similar articles, some are based on network protocols, need to understand session,cookie these things, for a novice is very cumbersome, until these things to understand, Enthusiasm is exhausted. The advantage of VB is that those who do not know the bottom of the computer quickly realize their program design, I found a relatively simple way to ask for an understanding of HTML markup Language, now to write their own experience in the sharing of friends, this method may be insignificant, may be helpful to you.

My approach is to use the control WebBrowser, I think a lot of people are familiar with it, after a new project you want to do is to add two controls, one is WebBrowser, the other is Scriptlet, the two controls with the use, you can complete this task, The IHTMLDocument2 object in Scriptlet can be used to obtain the HTML document in the WebBrowser control. The names of the two controls are called Microsoft HTML Object Library and Microsoft Internet Controls, respectively, in the Component dialog box.

After the two controls have been added, you will also need to know the WebBrowser event DocumentComplete, which is triggered after the entire Web page has been downloaded, which means that the event is executed after the page is finished, and that it can be successfully registered.

below to Eyou website free mailbox Registration as an example to implement my program design, new standard project to add a WebBrowser control to the form. All the code is as follows:

Dim II as Integer



Private Sub Form_Load ()

WebBrowser1.Navigate "Http://freemail.eyou.com/signup.html?bgp=%CE%D2%BD%D3%CA%DC&bgp_enable=on"

End Sub



Private Sub Webbrowser1_documentcomplete (ByVal pdisp as Object, URL as Variant)

Dim Doc as IHTMLDocument2

Set doc = webbrowser1.document

Dim tmp as String



If InStr (Doc.body.innerText, "Looking for a new username") > 0 Then

TMP = "sdfsdf23" + Trim (str$ (ii))

Doc. All.item ("UID"). focus

SendKeys tmp

SendKeys ' {Enter} '

End If



If InStr (Doc.body.innerText, "Enter your Profile") > 0 Then



Doc. All.item ("Password"). Value = "123456"

Doc. All.item ("Confirm"). Value = "123456"

Doc. All.item ("FirstName"). Value = "Tomcant"

Doc. All.item ("question"). Value = "What is your name"

Doc. All.item ("Answer"). Value = "My name is DDD"

Doc. All.item ("Year"). Value = "80"

Doc. All.item ("month"). Value = "3"

Doc. All.item ("Day"). Value = "18"

Doc. All.item (' Day '). focus

SendKeys ' {Enter} '

End If





If InStr (Doc.body.innerText, "Request mailbox Success") > 0 Then

II = II + 1

WebBrowser1.Navigate "Http://freemail.eyou.com/signup.html?bgp=%CE%D2%BD%D3%CA%DC&bgp_enable=on"

End If



End Sub

Eyou's Free mailbox Registration entry address is http://freemail.eyou.com/signup.html?bgp=%CE%D2%BD%D3%CA%DC&bgp_enable=on, so to be in form_ The Navigate method for using the WebBrowser control in the Load event.

Webbrowser1_documentcomplete is executed after the Eyou registration entry page is completed, in which there are three conditional statements, preceded by the following three sentences in three conditional statements:

Dim Doc as IHTMLDocument2

Set doc = webbrowser1.document

Dim tmp as String

DOC is defined as the IHTMLDocument2 object used to obtain the WebBrowser1 document, the TMP string is the user name in the circular registration, and the integer variable is defined at the beginning of the program, and after the completion of each registration, II plus 1 is appended to TMP to change the user name.

The first conditional statement is as follows:

If InStr (Doc.body.innerText, "Looking for a new username") > 0 Then

TMP = "sdfsdf23" + Trim (str$ (ii))

Doc. All.item ("UID"). focus

SendKeys tmp

SendKeys ' {Enter} '

End If

The first is to determine whether the registration entry page is implemented through InStr (Doc.body.innerText, "Looking for a new username") > 0 statement, Doc.body.innerText gets all the text on the page. If so, a user name is constructed. Doc. All.item ("UID"). Focus uses the username text box to get the focal point, where the UID is the ID of the text box, which is obtained by looking at the HTML source code, and therefore requires an understanding of the HTML markup Language. After using the User Name text box to gain focus, the SendKeys function simulates the keyboard to send a TMP string to the text box so that the username is completed and the return key is sent to submit the form. For the use of the SendKeys function, you can consult MSDN help.

The second conditional statement first determines whether the change page is a personal data fill the page, and then fill out the personal data, the method and fill in the same user name, get a text box ID fill in its value, finally submit the form.

The last conditional statement determines that the mailbox registration succeeds with the second plus one, and then the page is relocated to the registration entry page, which completes the loop.

The above code implements automatic registration submission.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.