이틀 동안 공부 한 후 다음 코드를 만들어 각 동료와 공유했습니다. 데이터 크롤링은이 세 가지 기능, 특히 Alexa Rosso (Strurl, id)
set r = server.createobject (microsoft.xmlhttp)
R. Open Get, URL, False,
R.SetRequestHeader Referer, URL
R.Send
str1 = b2s (r.responsebody)
str1 = 교체 (str1 ,,,)
Reg = New Regexp를 설정합니다
reg.multiline = true
reg.global = true
reg.ignorecase = true
str_top = <font color =#fb5e3c>
str_bottom = </font>
reg.pattern = & str_top & ((. |/n)*?) & str_bottom &
매치 설정 = reg.Execute (str1)
str1 =
일치하는 각 경기에 대해
str1 = match1.Value
다음
일치 = 아무것도 설정하지 않습니다
reg = 아무것도 설정하지 않습니다
str1 = replace (replace (str1, str_top,), str_bottom,)
conn.Execute (webtable set pr = '& str1 &'where id = & id)
종료 서브
하위 오류 (STR) SELECT CASE Str
사례 1
response.write <br> & nbsp; & nbsp; 검색 엔진이 비어 있습니다. <a href = mailto : [email protected]> [email protected] </a> 문의하십시오.
사례 2
response.write <br> & nbsp; & nbsp; 사이트 이름은 비어 있습니다. <a href = mailto : [email protected]> [email protected] </a> 문의하십시오.
사례 3
Response.write <br> & nbsp; & nbsp; 입력 한 검색 엔진은이 프로그램에서 지원되지 않습니다. <a href = mailto : [email protected]> [email protected] </a> </body </body <. /html>
사례 4
response.write <br> & nbsp; & nbsp; 알 수없는 오류 - 데이터를 크롤링 할 수 없습니다. /body> </html>
종료 선택
응답. 엔드
end subsub google (strurl, id, all) url = http : //www.google.cn/search? complete = 1 & hl = zh-cn & q = site%3a & strurl && meta =
str = gethttppage (url)
str =이면
conn.execute (webtable set google = '0'where id = & id)
또 다른
Reg = New Regexp를 설정합니다
reg.multiline = true
reg.global = false
reg.ignorecase = true
str_top = <td align = right nowrap> <font size = -1>
str_bottom = </font> </td> </tr> </table>
reg.pattern = & str_top & ((.)*) & str_bottom &
매치 설정 = reg.Execute (str)
일치하는 각 경기에 대해
str = match1.Value
다음
일치 = 아무것도 설정하지 않습니다
악기 (str, <html>) = 1 인 경우
str2 = 0
또 다른
str = split (str, </b>)
str1 = str (3)
str2 = split (str1, <b>) (1)
끝 If
str2 = 또는 len (str2)> 200 인 경우
conn.execute (webtable set google = '0'where id = & id)
또 다른
conn.execute (webtable set google = '& str2 &'where id = & id)
끝 If
끝 If
END SUBSUB BAIDU (str, id, all) 'all = n이면 print_do (baidu)'call print_do (baidu)
url = http : //www.baidu.com/s? wd = site%3a & str && cl = 3
또 다른
strext = split (str,.)
url = http : //www.baidu.com/s? wd = & strext (0) && cl = 3
끝 If
'response.write (<br> baidu의 URL : & url) isobjinstalled (asphttp.conn) = true
str = getAsphttppage (url)
또 다른
str = gethttppage (url)
끝 If
str =이면
호출 오류 (4)
또 다른
Reg = New Regexp를 설정합니다
reg.multiline = true
reg.global = false
reg.ignorecase = true
str_top = <td align = right nowrap>
str_bottom = </td>
reg.pattern = & str_top & ((. |/n)*?) & str_bottom &
매치 설정 = reg.Execute (str)
일치하는 각 경기에 대해
str = match1.Value
다음
일치 = 아무것도 설정하지 않습니다
reg = nothingresponse.write <br>을 설정하십시오
'응답 .write & nbsp; & nbsp;
str = 또는 len (str)> 200 인 경우
conn.execute (webtable set baidu = '0'where id = & id)
또 다른
악기 (str, 대략) = 0이면
keyw = 페이지
또 다른
keyw = 근사
끝 If
str = mid (str, (str, keyw) +1), (Instr (str, article) -instr (str, keyw) -1))
응답
conn.Execute (webtable set baidu = '& replace (replace (str ,,) ,,) &'where id = & id)
끝 If
끝 If
End Subsub Alexa (Strurl, id)
url = http : //www.alexa.com/data/details/traffic_details? q = & url = & strurl
set r = server.createobject (microsoft.xmlhttp)
R. Open Get, URL, False,
R.SetRequestHeader Referer, URL
R.Send
str1 = bytes2bstr (r.responsebody)
str1 = 교체 (str1 ,,,)
Reg = New Regexp를 설정합니다
reg.multiline = true
reg.global = true
reg.ignorecase = true
str_top = <!-당신은 알고 계셨습니까?
str_bottom = </span> <br>
reg.pattern = & str_top & ((. |/n)*?) & str_bottom &
매치 설정 = reg.Execute (str1)
str1 =
일치하는 각 경기에 대해
str1 = str1 & match1.Value
다음
일치 = 아무것도 설정하지 않습니다
reg = 아무것도 설정하지 않습니다
str1 = replace (str1, <!-알고 있습니까? Alexa는이 데이터를 프로그래밍 방식으로 제공합니다. http://aws.amazon.com/awis를 방문하십시오. Alexa Web Information Service에 대한 자세한 내용은->,).
str1 <>라면
str1 = replace (str1, <span class,)
str1 = replace (str1, </span> </span>,)
str1 = 교체 (str1 ,,)
str1 = 교체 (str1 ,,)
str1 = split (str1, <br>) (0)
cstr (오른쪽 (str1,7)) = </span> 인 경우
str1 = 왼쪽 (trim (str1), len (str1) -7)
끝 If
iSnumeric (str1)이면
num = str1
또 다른
csstxt = getalexacss ()
num =
str1 = split (str1, </span>)
i = 0에서 Ubund (str1)의 경우
str2 = str1 (i)
왼쪽 (str2, inst (str2, =)) <>
num = num & 왼쪽 (str2, instr (str2, =) -1)
str2 = 오른쪽 (str2, len (str2) -instr (str2, =))
끝 If
str3 = split (str2,>)
J = 0에서 Ubund (str3)의 경우
다음
str3 (0) <>라면
그렇지 않다면 (str3 (0))
악기 (csstxt, str3 (0)) = 0 인 경우
num = num & str3 (1)
끝 If
끝 If
끝 If
다음
끝 If
또 다른
num = 0
끝 If
sql = webtable set alexa = '& num &'where id = & id
response.write (<cript> alert ( '& sql &') </script>)
Conn.Execute (SQL)
종료 하위 기능 B2S (STR)
희미한 o
set o = server.createobject (adodb.stream)
O.type = 1
O. 모드 = 3
O. 오렌
O.Write Str
O.Position = 0
O.type = 2
O.Charset = GB2312
B2S = O.ReadText
O.Close
O = 아무것도 설정하지 않습니다
최종 기능 'Alexa의 스타일 시트를 얻으십시오
함수 getalexacss ()
url = http : //client.alexa.com/common/css/scramble.css
isobjinstalled (asphttp.conn) = true
str = getAsphttppage (url)
또 다른
str = gethttppage (url)
끝 If
getalexacss = str
END FUNCTIONSUB PRINT_DO (STR)
응답. <cript>
응답.
응답. 쓰기 {
response.write parent.do & str & .style.display = 'none';
응답}}
응답 </script>
response.write <Body LeftMargin = 0 TopMargin = 0 marginwidth = 0 marginheight = 0 bgcolor =#f2f2f2 onload = hiddenload ()>
종료 하위 기능 gethttppage (URL)
다음에 오류가 재개됩니다
희미한 HTTP
set http = server.createobject (microsoft.xmlhttp)
http.open get, url, false
http.send ()
http.readystate <> 4 인 경우
종료 기능
끝 If
gethttppage = bytes2bstr (http.responsebody)
HTTP = 아무것도 설정하지 않습니다
err.number <> 0 인 경우 err.clear
END FUNCUTFUNCER BYTES2BSTR (VIN)
Dim Bytesstream, Stringreturn
bytesstream = server.createobject (adodb.stream)
바이트 스트림. 타입 = 2
바이트 스트림
BYTESSTREAM.WRITETEXT VIN
바이트 스트림. 위치 = 0
bytestream.charset = gb2312
바이트 스트림. 위치 = 2
StringReturn = BytestReam.ReadText
바이트 스트림 .close
ByTessTream = Nothing을 설정합니다
BYTES2BSTR = StringReturn
END FUCTIONFTERMET GETASPHTTPPAGE (URL)
url =이면
종료 기능
끝 If
set httpobj = server.createobject (asphttp.conn)
'프록시 서버를 설정하고 프록시를 사용하여 인터넷에 액세스하는 사용자는이 옵션을 설정해야합니다.
proxyip = 1 인 경우
httpobj.proxy = 192.168.5.254 : 808
끝 If
httpobj.timeout = 45
httpobj.url = url
httpobj.requestmethod = get
getAphttppage = httpobj.geturl
httpobj = 아무것도 설정하지 않습니다
END FUCTUTFUNCER ISOBJINSTALLED (strclassString)
다음에 오류가 재개됩니다
isobjinstalled = false
err = 0
dim xtestobj
0 = err then
asphttpopen = 1이면
isobjinstalled = true
'응답. 현재 구성 요소 asphttp
또 다른
isobjinstalled = false
'응답. 현재 구성 요소 xmlhttp
끝 If
또 다른
isobjinstalled = false
'응답. 현재 구성 요소 xmlhttp
set xtestobj = nothing을 설정하면 종료하십시오
err = 0
엔드 기능