Analyze a Web site in Access case

Source: Internet
Author: User
Tags format exit insert integer interface variables query tagname
Access
Analyze a Web site in Access case





Problem:

How can I use Access to analyze a Web site, or submit a query on a Web site, and then store it in a database?
How do I download all the posts on the Dvbbs forum with Access?
How do I use ACCESS to write an irrigation program?




Method One:

The answer is very simple--dhtml programming.
One might ask, Access uses VBA, and how is a VBS used in DHTML to be universal? In fact, Vbs/vba are a subset of VB. In Access, just refer to


Microsoft Internet Controls
Microsoft HTML Object Library

, and then add the Microsoft Web Browser Control to the form

Well, here's an example of what I wrote about a database that reads an IP physical Geography query Site page to illustrate the application of the DHTML/Microsoft Web Browser Control in ACCESS.

What is the role of the Microsoft Web browser control? Mainly for the purpose of obtaining the Document object, DHTML operations are based on the Document object.

To complete the function of reading a Web page, we must understand several simple objects and attributes of DHTML
1. Document object: Represents this entire HTML document
2, the Body object: is the DOCUMENT object of the child object, which stores all the HTML displayed to the user to see the code
3, InnerText properties: The text displayed to the customer in the page, note: not HTML code yo
4, innerHTML properties: The HTML code that makes up the page
5. Object. All.length property: The number of all the element in the page. (All is used to represent all objects)

OK, then let's write the code, while analyzing it:
Option Compare Database
Dim Blnswitch as Boolean
Private Sub Command1_Click () is used to start the browsing feature
Me.WebBrowser3.Navigate ("Http://ip.loveroot.com/index.php?job=search")
End Sub


Private Sub Command11_click () writes the IP that needs to be searched to global variables
Splitip Text1.value
End Sub
Function Splitip (Strip) writes the IP that needs to be searched to global variables
Dim A () as String
Strip = Strip & "."
A = Split (strip, ".")

Dim I as Long
For 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) read results
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 the loop DOCUMENT get the required characters
For i = 0 to Dc.all.length-1
' Because the server rewrites 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) = "Official data query Results" Then
' Because the server rewrites 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, D C.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 get the data needed, write directly to the database with SQL statements
strSQL = "Update ipaddress set [ip1]= '" & Strip & "', [add]= ' & Stradd &" ' Where mark= ' last ']
CurrentProject.Connection.Execute strSQL
strSQL = "INSERT into 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
' Use DHTML InnerHTML to change the source code of the Web page, create a simple FORM, and then submit it to the server to continue querying the following IP
bd.innerhtml = "<form method= ' POST" action= ' index.php?job=search ' target= ' _parent ><input ' type= ' text ' name= ' Search_ip ' ><input type= ' submit ' value= ' search ' name= ' B1 ' ></form> '
' Enter the IP in the INPUT TEXT search_ip.
Dc.all.Item ("Search_ip"). Value = Strnewip
' Submit FORM to server with DHTML
Dc.all.Item ("B1"). Click
End Sub

Private Sub Form_Open (Cancel as Integer)
Text1.value = Nz (DLookup ("Ip1", "IPAddress", "[mark]= ' Last" & Me.caption & ""), "1.0.0.0")

End Sub

Private Sub Webbrowser3_downloadcomplete ()
' This event runs when the page is successfully downloaded to the local, when the DOCUMENT object
' has been completely read by the client browser, we can just get the InnerHTML in the Body object
If Len (STRNOWIP) = 0 Then
Splitip Text1.value
End If

If Check1. Value = True Then
Call Writelog ("61.12.15.117")
End If
End Sub

Function refreship () as String ' after searching for an IP, search for one of the following
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 (Lngsearchip (2), "0") & "." & Format (Lngsearchip (1), "0")
STRNOWIP = Refreship
Debug.Print Refreship
End Function





The following code please create a new module and COPY it in
Option Compare Database
Public Lngsearchip (4) as Long
Public Strnowip as String
Public strokaddress as String
Public Strokip as String
Public Blnstop as Boolean
Function 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= ' SE Tting ' "
CurrentProject.Connection.Execute strSQL
DoEvents
strSQL = "INSERT INTO IPADDRESS_OK (Ip1,enip1,[mark],[add]) VALUES ('" & RS ("Ip1") & "," & Str (RS ("Enip")) &am P ", ' Setting ', '" & RS ("Add") & "')"
CurrentProject.Connection.Execute strSQL
DoEvents
End If

STRADD1 = RS ("add")
StrIP1 = RS ("ip1")
LngENIP1 = RS ("Enip")
i = i + 1
Form_ control. Label4.caption = Str (Int (I/ia * 10000)/MB) & "%"
Rs. MoveNext
Loop
Rs. Close

strSQL = "Update Ipaddress_ok set Ip2=mid (Ip2,1,len (IP2)-2) & ' 255 '"
CurrentProject.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 strSQL
End Function


Function enaddr (Sip as String) as Double
' The problem of not connecting with the agent is still to be solved
' IP encoding a character to a long IP
On Error Resume Next
Dim str1 as String
Dim str2 as String
Dim 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)-1
End Function

Function deaddr (SIP)
' Converts encoded IP to a long integer to a 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



For example please refer to: 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 to search all IP and corresponding physical address and save it to the database.

Revision: Just on the web site, found that the interface has changed, and then revised the page to read the program.

For information about WebBrowser controls, refer to the following sections of MSDN in VB6
Internet Client SDK
Internet Tools & Technologies
Reusing the WebBrowser and MSHTML

Inet401/help/itt/ieprog/ieprog.htm#book_browsing (BOOKMARK)







Http://access911.net Webmaster Collection


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.