asp通用采集函數(shù)冗余版可以保存文件到本地
更新時(shí)間:2007年10月28日 16:24:35 作者:
<%
'名稱:asp通用采集函數(shù)冗余版,要精品版的有心人自己改
'作者:柳永法
'日期:2007-6-23
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage = BytesToBstr(t, "GB2312")
End Function
Function GetBody(url)
On Error Resume Next
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
With xmlhttp
.Open "Get", url, False, "", ""
.Send
.waitForResponse 1000
GetBody = .ResponseBody
End With
Set xmlhttp = Nothing
End Function
Function BytesToBstr(Body, Cset)
On Error Resume Next
Dim objstream
Set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write Body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function
Function getHTTPimg(url)
On Error Resume Next
Dim xmlhttp
Set xmlhttp = server.CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open "GET", url, false
xmlhttp.send()
If xmlhttp.Status<>200 Then Exit Function
getHTTPimg = xmlhttp.responseBody
Set xmlhttp = Nothing
If Err.Number<>0 Then Err.Clear
End Function
Function Save2Local(from, tofile)
Dim geturl, objStream, imgs
geturl = Trim(from)
imgs = gethttpimg(geturl)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objstream.Write imgs
objstream.SaveToFile tofile, 2
objstream.Close()
Set objstream = Nothing
End Function
%>
<%
NowDir = server.mappath("/")
Call Save2Local("http://www.baidu.com/img/logo.gif", NowDir & "baidulogo.gif")
Call Save2Local("http://flash.jninfo.net/images/banner.swf", NowDir & "banner.swf")
Call Save2Local("http://www.dbjr.com.cn.com/", NowDir & "jb51.htmll")
response.Write getHTTPPage("http://www.dbjr.com.cn/")
%>
'名稱:asp通用采集函數(shù)冗余版,要精品版的有心人自己改
'作者:柳永法
'日期:2007-6-23
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage = BytesToBstr(t, "GB2312")
End Function
Function GetBody(url)
On Error Resume Next
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
With xmlhttp
.Open "Get", url, False, "", ""
.Send
.waitForResponse 1000
GetBody = .ResponseBody
End With
Set xmlhttp = Nothing
End Function
Function BytesToBstr(Body, Cset)
On Error Resume Next
Dim objstream
Set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write Body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function
Function getHTTPimg(url)
On Error Resume Next
Dim xmlhttp
Set xmlhttp = server.CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open "GET", url, false
xmlhttp.send()
If xmlhttp.Status<>200 Then Exit Function
getHTTPimg = xmlhttp.responseBody
Set xmlhttp = Nothing
If Err.Number<>0 Then Err.Clear
End Function
Function Save2Local(from, tofile)
Dim geturl, objStream, imgs
geturl = Trim(from)
imgs = gethttpimg(geturl)
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objstream.Write imgs
objstream.SaveToFile tofile, 2
objstream.Close()
Set objstream = Nothing
End Function
%>
<%
NowDir = server.mappath("/")
Call Save2Local("http://www.baidu.com/img/logo.gif", NowDir & "baidulogo.gif")
Call Save2Local("http://flash.jninfo.net/images/banner.swf", NowDir & "banner.swf")
Call Save2Local("http://www.dbjr.com.cn.com/", NowDir & "jb51.htmll")
response.Write getHTTPPage("http://www.dbjr.com.cn/")
%>
相關(guān)文章
光碟工具 Alcohol 120% v1.9.6.4719 下載(附序列號(hào)注冊(cè)碼)
光碟工具 Alcohol 120% v1.9.6.4719 下載(附序列號(hào)注冊(cè)碼)...2007-02-02msxml3.dll 錯(cuò)誤 800c0005 解決方案
在運(yùn)用xmlhttp組件編寫程序中,會(huì)碰到msxml3.dll 錯(cuò)誤 800c0005系統(tǒng)未找到指定的資源。這種錯(cuò)誤,網(wǎng)上對(duì)這種錯(cuò)誤的產(chǎn)生原因有很多鐘解釋,大體說(shuō)是因?yàn)榉阑饓騏DP站口權(quán)限造成了,也說(shuō)了相應(yīng)的解決辦法2006-08-08asp下以Json獲取中國(guó)天氣網(wǎng)天氣的代碼
這兩天搞個(gè)天氣預(yù)報(bào),記得以前用.net版本有種是抓取百度天氣寫入txt,再讀取。時(shí)間久了,txt很多。感覺不是很好。2010-07-07