国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用 Access 分析網站一例

2024-07-21 02:09:31
字體:
來源:轉載
供稿:網友

用 access 分析網站一例

 

 

問題:

如何用 access 分析一個網站,或者在網站上提交一個查詢,得到結果后存儲進數據庫哪?
如何用 access 下載 dvbbs 論壇上所有的帖子?
如何用 access 編寫灌水程序?
 



方法一:

答案非常簡單—— dhtml 編程。
有人可能問了,access 使用的是 vba ,而 dhtml 中使用的是 vbs 怎么可能通用哪?其實 vbs / vba 都是 vb 的子集。在 access 中只要引用


microsoft internet controls
microsoft html object library

即可,然后在窗體上加入 “microsoft web 瀏覽器”控件

好了,下面就以我寫的一個讀取某 ip 物理地域查詢網站頁面的數據庫為例說明 dhtml / “microsoft web 瀏覽器”控件在 access 的應用吧。

“microsoft web 瀏覽器”控件的作用是什么哪?主要就是為了獲得 document 對象的,dhtml 的操作都是以 document 對象為運行基礎的。

要完成讀取網頁的功能我們必須了解 dhtml 的幾個簡單的對象以及屬性
1、document 對象:代表這整個 html 文檔
2、body 對象:是 document 對象的子對象,里面存儲著所有顯示給用戶看的 html 代碼
3、innertext 屬性:頁面中顯示給客戶看的文本,注意:不是 html 代碼呦
4、innerhtml屬性:構成頁面的 html 代碼
5、對象.all.length屬性:頁面中所有 element 的個數。(all 用于表示所有對象)

ok ,接下來就讓我們一邊寫代碼,一邊分析吧:
option compare database
dim blnswitch as boolean
private sub command1_click()        '用于啟動瀏覽功能
    me.webbrowser3.navigate ("http://ip.loveroot.com/index.php?job=search")
end sub


private sub command11_click()   '將需要搜索的ip 寫入全局變量
    splitip text1.value
end sub
function splitip(strip) '將需要搜索的ip 寫入全局變量
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)         '讀取結果
    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
    
    '循環 document 中所有的元素獲取需要的字符
    for i = 0 to dc.all.length - 1
        '由于該服務器重寫界面,我改了一下分析代碼
        'if dc.all(i).tagname = "p" and left(dc.all(i).innertext, 4) = "查詢結果" then
        if dc.all(i).tagname = "p" and left(dc.all(i).innertext, 8) = "官方數據查詢結果" then
            '由于該服務器重寫界面,我改了一下分析代碼
            '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, "查詢結果:") + 6, instr(1, dc.all(i).innertext, "(") - instr(1, dc.all(i).innertext, "查詢結果:") - 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 終于得到需要的數據了,用 sql 語句直接寫入數據庫吧
            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
    '利用 dhtml 的 innerhtml 來更改網頁的源代碼,建立一個簡單的 form ,然后提交給服務器,繼續查詢下面的 ip
    bd.innerhtml = "<form method='post' action='index.php?job=search' target='_parent'><input type='text' name='search_ip' ><input type='submit' value='查詢' name='b1'></form>"
    '在 input text search_ip 中填入 ip。
    dc.all.item("search_ip").value = strnewip
    '用 dhtml 提交 form 到服務器
    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()
    '該事件在頁面成功下載到本地時運行,這時候 document 對象
    '已經完全被客戶端瀏覽器讀取了,我們只要獲取 body 對象中的 innerhtml 即可
    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      '搜索完一個ip以后再搜索下面一個
    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





以下代碼請新建一個模塊后 copy 進去
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='setting'"
            currentproject.connection.execute strsql
            doevents
            strsql = "insert into ipaddress_ok (ip1,enip1,[mark],[add]) values('" & rs("ip1") & "'," & str(rs("enip")) & ",'setting','" & rs("add") & "')"
            currentproject.connection.execute strsql
            doevents
        end if
            
        stradd1 = rs("add")
        strip1 = rs("ip1")
        lngenip1 = rs("enip")
        i = i + 1
        form_控制.label4.caption = str(int(i / ia * 10000) / 100) & "%"
        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
    '用代理無法連接的問題還要解決
    '將字符的 ip 編碼為長整的 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)
    '將編碼為長整的 ip 重現轉換為字符型的 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



示例請參考:http://access911.net/down/eg/user_dhtml_search_ip.rar

上述程序會自動去 http://ip.loveroot.com/index.php?job=search 搜索所有的 ip 以及對應的物理地址并保存到數據庫中

修訂:剛才上了一下網站,發現界面竟然改了,又重新修改了一下讀取頁面的程序。

關于 webbrowser 控件的資料請參考 vb6 中 msdn 的以下章節 
internet client sdk 
internet tools & technologies
reusing the webbrowser and mshtml

inet401/help/itt/ieprog/ieprog.htm#book_browsing(bookmark)


 




http://access911.net 站長收藏
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 齐河县| 建湖县| 从江县| 赞皇县| 濮阳县| 宜州市| 铜梁县| 清新县| 宣汉县| 威海市| 马鞍山市| 广宁县| 赤峰市| 象州县| 尼木县| 开鲁县| 兴国县| 濮阳市| 天长市| 秦皇岛市| 安福县| 隆回县| 清原| 荆州市| 井冈山市| 孟津县| 平原县| 永城市| 抚顺县| 新巴尔虎右旗| 临西县| 临高县| 常州市| 龙游县| 崇阳县| 广宗县| 环江| 麦盖提县| 威宁| 西青区| 绥芬河市|