An example of an Access analysis website

zhaozj2021-02-16  46

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 = "

"Fill in IP in Input Text Search_IP.

Dc.all.Item ("Search_ip"). Value = strnewip 'Submit Form to Server Dc.all.Item ("B1") with DHTML. Clicel AS Integer Text1.Value = NZ (Dlookup "IP1", "ipaddress", "[mark] = 'Last" & me.caption & ""), "1.0.0.0") End Sub Private Sub webbrowser3_downloaduniccomplete () This event is running successfully on the page At this time, the Document object 'has been readily read by the client browser, and we only get the innerhtml in the Body object, if you can IF Len (Strnowip) = 0 Then splitip text1.value end if check1.value = true kil t ("61.12.15.117") Endness Sub Function Refreship () AS String 'Search after a IP Search below A DIM I as Long LngSearchip (2) = LNGSearchip (2) 1 for i = 2 To 4 if LNGSearchip I)> = 256 Then LngSearchip (i) = 0 LNGSearchip (i 1) = LNGSearchip (i 1) 1 End if Next I Refreship = Format (LNGSearchip (4), "0") & "& Format (LNGSearchip (3), "0") & "." & format (2), "0") & "." & format (LNGSearchip (1), "0") strNowip = Refreship debug.print Refresh Ipend Function The following code Please create a new module Copy

Option Compare DatabasePublic lngSearchIP (4) As LongPublic strNowIP As StringPublic strOKAddress As StringPublic strOKIP As StringPublic blnStop As BooleanFunction writeOKIP () Dim rs As New ADODB.Recordset Dim strSql As String strSql = "select * from ipaddress order by enip" rs.Open strSql , CurrentProject.Connection, 1, 1 Dim strAdd1 As String Dim strIP1 As String Dim lngENIP1 As Long Dim strState As String strState = "start" Dim i As Long Dim iA As Long iA = rs.RecordCount Do Until rs.EOF If blnStop = TRUE THEN EXIT FUNCTION IF stradd1 <> rs ("add") THEN strsql = "Update ipaddress_ok set ip2 = '" & strip1 & ", enip2 =" & str (lngenip1) & ", mark =' 'Where mark =' Setting '"CurrentProject.connection.execute strsql doevents strsql =" Insert INTO ipaddress_ok (IP1, Enip1, [Mark], [Add]) VALUES (' "& r (" IP1 ") &" ', "& STR (RS) "Enip")) & ", 'setting', '" & rs ("add") & "')" Currentp ROject.Connection.execute strsql doevents end if stradd1 = rs ("add") strip1 = rs ("IP1") LNGENIP1 = RS ("Enip") i = i 1 Form_ control.label4.caption = Str (int (INT) I / IA * 10000) / 100) & "%" rs.movenext loop rs.close strsql = "Update ipaddress_ok set ip2 = MID (IP2, 1, LEN (IP2) -2) & '255'" CURRENTPROROJECT.CONNECTION. Execute strsql strsql =

"Update ipaddress_ok set enip1 = enaddr (ip1)" CurrentProject.Connection.Execute strSql strSql = "update ipaddress_ok set enip2 = enaddr (ip2)" CurrentProject.Connection.Execute strSqlEnd Function Function enaddr (Sip As String) As Double 'agents not used The connection problem also wants to solve the 'to encode the IP of the character to long-term IP ON Error Resume Next Dim str1 AS String Dim str2 AS STRING STR3 AS STRING DIM STR4 AS STRING SIP = CSTR (SIP) STR1 = Left (SIP, CINT (INSTR (SIP, ") - 1)) SIP = MID (SIP, CINT (INSTR (SIP,")) 1) STR2 = Left (SIP, CINT (INSTR (SIP, ")) - 1) SIP = MID (SIP, CINT (INSTR (SIP, ")) 1) STR3 = Left (SIP, CINT (INSTR (SIP,")) - 1) STR4 = MID (SIP, CINT (INSTR (SIP, ")) 1) enaddr = clng (str1) * 256 * 256 * 256 clng (str2) * 256 * 256 clng (str3) * 256 ClNG (str4) - 1END Function function (STR4) DEADDR (SIP) 'converts the encoded IP reproduction into character type IP DIM S1, S21, S2, S31, S3, S4 SIP = SIP 1 S1 = Int (SIP / 256/256/256) S21 = S1 * 256 * 256 * 256 S2 = INT ((SIP - S21) / 256 / 256) S31 = S2 * 256 * 256 S21 S3 = INT ((SIP - S31) / 256) S4 = SIP - S3 * 256 - S31 DeAddr = CSTR (S1) "." CSTR (S2) ". " CSTR (S3) ". " CSTR (S4) End function example please refer: http://access911.net/down/eg/user_dhtml_search_ip.rar The above program will automatically go to http://ip.loveroot.com /index.php?job=search Search all IPs and corresponding physical addresses and save them to the database: I just got a website, I found that the interface turned, and revised a program that read the page.

Information about the WebBrowser control in VB6 please refer to the following sections MSDN Internet Client SDK Internet Tools & TechnologiesReusing the WebBrowser and MSHTML inet401 / help / itt / ieprog / IEProg.htm # book_browsing (BOOKMARK) http://access911.net Master Collection

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

New Post(0)