天天看點

asp資料采集

asp資料采集

資料采集程式

asp資料采集

'On Error Resume Next

asp資料采集

Server.Scripttimeout=300

asp資料采集
asp資料采集

'---------------------------------------------------------------------

asp資料采集

'采集資料

asp資料采集

Function getHTTPData(url) 

asp資料采集

    dim http 

asp資料采集

    set http=Server.createobject("Msxml2.XMLHTTP")

asp資料采集

    if instr(url,"http://")=0 then url="http://"&url

asp資料采集

    Http.open "GET",url,false 

asp資料采集

    Http.send() 

asp資料采集

    if Http.Status<>200  then exit function 

asp資料采集

    getHTTPData=bytesToBSTR(Http.responseBody,"UTF-8")

asp資料采集

    set http=nothing

asp資料采集

    if err.number<>0 then err.Clear

asp資料采集

    sCharset="" 

asp資料采集

End function

asp資料采集

'---------------------------------------------------------------------        

asp資料采集

Function BytesToBstr(body,Cset)

asp資料采集

    dim objstream

asp資料采集

    set objstream = Server.CreateObject("adodb.stream")

asp資料采集

    objstream.Type = 1

asp資料采集

    objstream.Mode =3

asp資料采集

    objstream.Open

asp資料采集

    objstream.Write body

asp資料采集

    objstream.Position = 0

asp資料采集

    objstream.Type = 2

asp資料采集

    objstream.Charset = Cset

asp資料采集

    BytesToBstr = objstream.ReadText 

asp資料采集

    objstream.Close

asp資料采集

    set objstream = nothing

asp資料采集

End Function

asp資料采集

'---------------------------------------------------------------------    

asp資料采集

'伺服器登入

asp資料采集

Function login(url) 

asp資料采集
asp資料采集
asp資料采集
asp資料采集
asp資料采集
asp資料采集

    if Http.Status<>200 then exit function 

asp資料采集
asp資料采集
asp資料采集
asp資料采集
asp資料采集

'正則替換

asp資料采集

Function ReplaceText(fString,patrn, replStr)

asp資料采集

    Set regEx = New RegExp

asp資料采集

    regEx.Pattern = patrn

asp資料采集

    regEx.IgnoreCase = True

asp資料采集

    regEx.Global = True

asp資料采集

    ReplaceText = regEx.Replace(fString, replStr)

asp資料采集
asp資料采集
asp資料采集

'去标簽 包括内容

asp資料采集

Function ReplaceTag(str, tag)

asp資料采集
asp資料采集

    regEx.Pattern = "<"&tag&"[^>]*?>.*?<\/"&tag&">"

asp資料采集
asp資料采集
asp資料采集

    ReplaceTag=regEx.Replace(str, "")

asp資料采集
asp資料采集
asp資料采集

'去标簽 不包括内容

asp資料采集

Function ReplaceTab(str, tag)

asp資料采集
asp資料采集

    regEx.Pattern = "<\/?"&tag&"[^>]*>"

asp資料采集
asp資料采集
asp資料采集

    ReplaceTab=regEx.Replace(str, "")

asp資料采集
asp資料采集
asp資料采集

'去标簽屬性 保留标簽

asp資料采集

Function ReplaceinnerTag(str, tag)

asp資料采集
asp資料采集

    regEx.Pattern = "(<\/?"&tag&")[^>]*>"

asp資料采集
asp資料采集
asp資料采集

    ReplaceinnerTag=regEx.Replace(str, "$1>")

asp資料采集
asp資料采集
asp資料采集

'按正則取資料

asp資料采集

Function getText(fString, patrn,n) 

asp資料采集

    dim Matches, tStr

asp資料采集

    tStr = fString

asp資料采集

    Set re = New Regexp

asp資料采集

    re.IgnoreCase = True

asp資料采集

    re.Global = True

asp資料采集

    re.Pattern =  patrn

asp資料采集

    set Matches = re.Execute(tStr)

asp資料采集

    set re = nothing 

asp資料采集

    rStr = ""

asp資料采集

    For Each Match in Matches

asp資料采集

        rStr = Match.SubMatches(n)

asp資料采集

        exit for

asp資料采集

    Next

asp資料采集

    getText = rStr

asp資料采集
asp資料采集
asp資料采集

'資料過濾

asp資料采集

Function Encode_text(str)

asp資料采集

    If Isnull(str) Then

asp資料采集

        Encode_text = ""

asp資料采集

        Exit Function 

asp資料采集

    End If

asp資料采集

    str = ReplaceText(str, "<\/?br[^>]*>" , vbCrlf )

asp資料采集

    str = ReplaceText(str, "<\/?p[^>]*>" , vbCrlf )

asp資料采集

    str = ReplaceTab(str, "[a-zA-Z]")

asp資料采集

    str = ReplaceText(str, "\n\s*\r" ,Chr(10)&Chr(13))

asp資料采集

    str = Replace(str, "&" , "&" )

asp資料采集

    str = Replace(str, ";" , ";" )

asp資料采集

    str = Replace(str, "&" , "&" )

asp資料采集

    str = Replace(str,Chr(34), """ )

asp資料采集

    str = Replace(str, "'" , "'" )

asp資料采集

    str = Replace(str, "<" , "<" )

asp資料采集

    str = Replace(str, ">" , ">" )

asp資料采集

    str = Replace(str, "(" , "(" )

asp資料采集

    str = Replace(str, ")" , ")" )

asp資料采集

    str = Replace(str, "*" , "*" )

asp資料采集

    str = Replace(str, "%" , "%" )

asp資料采集

    str = Replace(str,vbCrlf, "<br/>" )

asp資料采集

    Encode_text = str

asp資料采集
asp資料采集
asp資料采集

'通過Matches取資料

asp資料采集

dim Matches

asp資料采集

sub setMatches(str,sRe)

asp資料采集
asp資料采集
asp資料采集
asp資料采集

    re.Pattern =  sRe

asp資料采集

    set Matches = re.Execute(str)

asp資料采集

    set re=nothing 

asp資料采集

end sub

asp資料采集

例子

asp資料采集

'例子

asp資料采集

call setMatches(textcontent, re)

asp資料采集

For Each Match in Matches

asp資料采集

    response.write Match.value

asp資料采集

Next

繼續閱讀