Lecture 2: How to use VB’s webbrowser to submit a web page containing a username and password
Last time we knew how to open a web page, today we will take a look at how to take the first step to making money.
Here we start taking steps:
1. First open VB and create a new project.
2. Right-click on the toolbar and select Components (I am using the Chinese version of VB) or select the Project menu and click Components
3. Find Microsoft Internet Controls, select it in front, and then confirm it. You will see an additional earth-like icon on the toolbar. Our future implementation will all revolve around it.
4. Add a WebBrowser1 to Form1, and then add a command1 to Form1.
5. Add the following code to Form1: (The above are all mentioned in our previous lecture, so you should be familiar with them)
'----------start-----------
Private Sub Command1_Click()
Dim vDoc, vTag
Dim i As Integer
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.length - 1 'Detect all tags
If UCase(vDoc.All(i).tagName) = "INPUT" Then 'Find the input tag
Set vTag = vDoc.All(i)
If vTag.Type = "text" Or vTag.Type = "password" Then 'See if it is what we need
Select Case vTag.Name 'According to the name of the tag, check mark operation
Case "EMAILADD"
vTag.Value = "[email protected]" 'Write your e-mail here
Case "PASSWD"
vTag.Value = "password" 'Write your password here
End Select
ElseIf vTag.Type = "submit" And vTag.Name = "SUB" And vTag.Value = "Subscribe" Then
'Find the submit button
vTag.Select 'You can also do without this
vTag.Click 'Click to submit, everything is OK
End If
End If
Next i
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://dhunter.51.net"
End Sub
'----------Finish-----------
6. Of course it is a test. Click the run button. We can see that our webbrowser has opened http://dhunter.51.net. Wait until the basic download of the web page is completed and then click the command1 button. Our lovely webbrowser will input what we just entered. Your e-mail and password have been submitted to the webpage. Have you seen that the subscription was successful? That's the sign of victory.
Okay, let’s write this much for now. Next time we will take a look at how to use webbrowser to find the hyperlink in a web page, which corresponds to the money-making link.
Appendix (related information):
As you can see, this time we are using the subscription mailing list on http://dhunter.51.net. Here is the source code of this webpage:
<form method="post" action="http://ml.xilu.com/cgi-bin/ml/client">
<p align="center"><font size="2">
<input type="hidden" name="USERID" value="dhunter">
Email:
<input type="text" name="EMAILADD" value="your email">
<br>
password:
<input type="password" name="PASSWD" value="******">
<br>
</font><font size="2">
<input type="submit" value="Subscribe" name="SUB">
<input type="submit" value="Unsubscribe" name="UNSUB">
</font></p>
</form>
The tags with input inside all accept input. Our main task here is to find them and operate on them.