采集程序【ASP】
采集程序
原理
采集程序实际上是通过了XML中的XMLHTTP组件调用其它网站上的网页。比如新闻采集程序,很多都是调用了sina的新闻网页,并且对其中的html进行了一些替换,同时对广告也进行了过滤。用采集程序的优点有:无须维护网站,因为采集程序中的数据来自其他网站,它将随着该网站的更新而更新;可以节省服务器资源,一般采集程序就几个文件,所有网页内容都是来自其他网站。缺点有:不稳定,如果目标网站出错,程序也会出错,而且,如果目标网站进行升级维护,那么采集程序也要进行相应修改;速度,因为是远程调用,速度和在本地服务器上读取数据比起来,肯定要慢一些。
一、事例
下面就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.google的html内容
Dim Url,Html
Url="http://ww
相关文档:
<%
for i=1 to rs.recordCount '变量i从1循环到数据库中的全部记录数
if (i mod 1 =1) then '每个tr即每行显示1个记录,可根据需要自行修改, 将左边的1修改为2即显示两行。
response.write "<tr align='center'>"
end if
%>
此处为要循环的内容
<%if (i mod 1 = 0) then ......
添加、删除、修改使用
db.Execute(Sql)命令执行操作
╔----------------╗
☆ 数据记录筛选 ☆
╚----------------╝
注意:单双引号的用法可能有误(没有测式)
Sql = "Select
Distinct
字段名 from 数据表"
Distinct函数,查询数据库存表内不重复的记录
......
<!--#include file="conn.asp"-->
<%
if request.Form("username")="" or request.form("password")="" then
response.Write("<script>alert('您好,不能为空
');location.href='index.html';</script>")
end if
%>
<%
di ......
Dim FilePath,FileName
Set ObjFileStream = Server.CreateObject("ADODB.Stream")
ObjFileStream.Type = 1
ObjFileStream.Mode = 3
ObjFileStream.open
ObjFileStream.LoadfromFile FilePath&"\"&FileName&".doc"
ObjFileStream.Position = 0
response.binarywrite  ......
'SQL防注入函数,调用方法,在需要防注入的地方替换以前的request("XXXX")为SafeRequest("XXXX")
'www.yongfa365.com
Function
SafeRequest(ParaValue)
ParaValue =
Trim
(
Request
(Pa ......