For Beginners: VB How to operate Web page Browse submit ———: in Baidu automatic search

Source: Internet
Author: User
Tags blank page

Recently wrote something about the automatic submission of Web pages and other issues, will not write on the internet to find, found that the code is disorderly, there is no organization, although their own program is finished, but dare not exclusive, ventured swim, master Mo xiào. Gossip less, to some serious, first of all, a brief description of the common Web page we use.

The first is some of the controls that we want to fill out, select options, drop-down lists, and so on.

First, get the Web source code: The General right-click to see, of course, some do not, there are a lot of alternative methods, really do not try this code:

WebBrowser1.Document.body.createtextrange (). HTMLText

Second, observe the code to find what we want:

Take Baidu homepage as an example:

1. Observation Homepage:

We're going to fill in a text box, then click the Search button

2, right-click to view the source code (a lot of code, not all posted), the key part:

text box

<input type=text name=wd class=ff size=35 maxlength=100>

Button

<input type=submit value= Baidu Search >

3. Write code:

First of all, locate our approach:

You can open a new IE window (using the Shell "Explorer www.baidu.com") and get the Web object (available on the code)

We do this: Open the Web page inside the program (add the Microsoft Internet controls part (that is, the WebBrowser control) to the project, named MDEMOWB)

It is easier to fill in the text box. Because the page code explicitly gives the name of the text control: NAME=WD, such as a downward use:

WBDOCUMENT.BODY.ALL ("WD"). Value = "123"

and submitted there, it is more "disgusting", there is no explicit control ID or name, but the very clear page code is input type=submit, which indicates that the role of the button is to submit the Web page, it is good to do, use the following call to achieve the same function:

Wbdocument.forms (0). Submit

At this point, problem solving

The complete code is as follows: (the code is relatively simple, so do not provide download, everyone copy is good)

' This procedure was written by Zcsor on January 13, 2007
' qq:47493585
' E-mail:shaoyan5@163.com
' Blog:http://blog.csdn.net/zcsor
' Forwarding please keep the author above information


'********************************************************************
' DEMO1: Fill out the form and submit
'********************************************************************
' Citation page: www.baidu.com
' Note the following paragraph in the source code of the webpage:
' <input type=text name=wd class=ff size=35 maxlength=100>
' <input type=submit value= Baidu Search >

' Add the Microsoft Internet controls part (that is, the WebBrowser control) to the project, named Mdemowb

' WebBrowser Control Document object
Dim Wbdocument as Variant

Private Sub Cmdaddtext_click ()
Mdemowb.navigate "Www.baidu.com"
End Sub


Private Sub Form_Load ()
' Initialize browsing with blank pages
Mdemowb.navigate "About:blank"
End Sub

Private Sub Mdemowb_documentcomplete (ByVal pdisp as Object, URL as Variant)
' Skip when opening a blank page
If URL <> "http://www.baidu.com/" then Exit Sub
' Wait for the data to download
Do
If not Mdemowb.busy then Exit do
DoEvents
Loop

' Get Document Object
Set wbdocument = mdemowb.document

' Fill out the form, where WD is the first line in the page code NAME=WD WD, set its value by the control name
WBDOCUMENT.BODY.ALL ("WD"). Value = "123"

' Submit the form, where the submission method is called (second line type=submit), there is generally no problem with the current version of IE, but different versions of the browser may not succeed
Call Wbdocument.forms (0). Submit
End Sub

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.