An example of an Access analysis website
problem:
How to analyze a website with Access, or submit a query on the website, get the result storage into the database? How to download all the posts on the DVBBS forum with Access? How to write a filling program with Access?
method one:
The answer is very simple - DHTML programming. Some people may ask, Access uses VBA, and how can VBS in DHTML? In fact, VBS / VBA is a subset of VB. In Access, just reference the Microsoft Internet ControlSmicrosoft HTML Object Library, then add the "Microsoft Web Browser" control on the form, let's take a database that I wrote an IP physical area query website page as an example. Note the DHTML / "Microsoft Web Browser" control in Access applications. What is the role of the "Microsoft Web Browser" control? Mainly in order to obtain Document objects, DHTML operations are based on Document objects. To complete the function of reading web pages, we must understand several simple objects of DHTML and properties 1, Document object: Represent this entire HTML document 2, Body object: is the child object of the Document object, store all display to users. HTML code 3, InnerText property: The text displayed to the customer is displayed, Note: Not HTML code 呦 4, InnerHtml property: HTML code 5, object. Allow.Length property: Number of all Element in the page. (All is used to represent all objects) OK, let us write code while writing:
Option Compare DatabaseDim blnSwitch As BooleanPrivate Sub Command1_Click () 'is used to start browsing Me.WebBrowser3.Navigate ( "http://ip.loveroot.com/index.php?job=search")End Sub Private Sub Command11_Click ()' Write the IP written to search for global variables splitip text1.valueEnd Subfunction Splitip (Strip) 'Write the IP of Search to Write Global Variables DIM A () AS Stringstrip = Strip & "." A = Split (Strip, ".") DIM I as longfor i = 0 to Ubound (a) IF a (i) = "" "THEN A (i) =" 0 "LNGSearchip (4 - i) = ClNG (A (i)) Next I end function Sub Writelog ip1 As String) 'reading result Dim dc As mSHTML.HTMLDocument Dim Bd As MSHTML.HTMLBody Dim El As MSHTML.HTMLElementCollection Dim strip As String Dim strAdd As String Dim strSql Dim i As Long Set dc = WebBrowser3.Document Set Bd = dc .BODY DIM LNGSTART AS long 'All elements in loop Document Get required character for i = 0 to dc.all.length - 1' Due to the server overwriting the interface, I changed the analysis code 'if dc.all (i ) .tagname = "p" and left (dc.all (i) .innerText, 4) = "Query results" Then IF dc.all (i) .tagname = "p" and left (Dc.all (i) .innertext, 8) = "The official data query result" Then 'Due to the server overwriting the interface, I changed the analysis code' stradd = MID (Dc.all (i) .innertext, Instr. 1, DC.all (i) .innertext, "(") 2, INSTR (1, Dc.all (i) .innertext, ")") - INSTR (1, Dc.all (i) .innertext, " (") - 3) 'Strip = MID (Dc.all (i) .innertext, INSTR (1, Dc.all (i) .innertext," Query Results: ") 6, INSTR (1, Dc.all i) .innertext, "(") - INSTR (1, Dc.all (i) .innertext, "Query results:") - 7) stradd =
Right (Dc.all (i) .innertext, len (dc.all (i) .innertext) - INSTR (DC.all (i) .innertext, "-") - 3) Strip = strnowip labelsip.caption = strip & Stradd 'OK finally got required data, written directly with SQL statement Strasql = "Update ipaddress set [ip1] ='" & strip & "', [add] ='" & stradd & "WHERE MARK = 'Last' "CurrentProject.connection.execute strsql strsql =" Insert IPADDRESS ([IP1], [Add], [Mark], [Enip]) VALUES ('"& strip &",' "& stradd &" ' , 'no', "& CStr (enaddr (strip)) &") "CurrentProject.Connection.Execute strSql Exit for End If Next i Dim strNewIP As String strNewIP = refreshIP On Error Resume Next 'to change the use of innerHTML DHTML pages Source code, establish a simple form, then submit it to the server, continue to query the following IP bd.innerhtml = "