网络编程
位置:首页>> 网络编程>> Asp编程>> asp 小偷采集程序原理与常用函数方法

asp 小偷采集程序原理与常用函数方法

 来源:asp之家 发布时间:2011-03-06 10:36:00 

标签:asp,小偷采集,函数

用采集程序的优点有:无须维护网站,因为采集程序中的数据来自其他网站,它将随着该网站的更新而更新;可以节省服务器资源,一般采集程序就几个文件,所有网页内容都是来自其他网站。缺点有:

不稳定,如果目标网站出错,程序也会出错,而且,如果目标网站进行升级维护,那么采集程序也要进行相应修改;速度,因为是远程调用,速度和在本地服务器上读取数据比起来,肯定要慢一些。

一、事例

下面就XMLHTTP在ASP中的应用做个简单说明

代码如下:

<% 
'常用函数 
'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码 
function getHTTPPage(url) 
dim Http 
set Http=server.createobject("MSXML2.XMLHTTP") 
Http.open "GET",url,false 
Http.send() 
if Http.readystate<>4 then 
exit function 
end if 
getHTTPPage=bytesToBstr(Http.responseBody,"GB2312") 
set http=nothing 
if err.number<>0 then err.Clear 
end function 
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换 
Function BytesToBstr(body) 
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 = "GB2312" '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP组件调用有中文字符的网页得到的将是乱码 
BytesToBstr = objstream.ReadText 
objstream.Close 
set objstream = nothing 
End Function 
'下面试着调用词典网 http://www.cidianwang.com的html内容 
Dim Url,Html 
Url="http://www.cidianwang.com"; 
Html = getHTTPPage(Url) 
Response.write Html 
%> 

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com