当前位置: 移动技术网 > IT编程>开发语言>Asp > Asp生成RSS的类_给网站加上RSS第1/2页

Asp生成RSS的类_给网站加上RSS第1/2页

2017年12月12日  | 移动技术网IT编程  | 我要评论

什么是rss?
rss是站点用来和其他站点之间共享内容的一种简易方式(也叫聚合内容),通常被用于新闻和其他按顺序排列的网站,例如blog。一段项目的介绍可能包含新闻的全部介绍等。或者仅仅是额外的内容或者简短的介绍。这些项目的链接通常都能链接到全部的内容。网络用户可以在客户端借助于支持rss的新闻聚合软件(如feeddemon、sharpreader,newzcrawler),在不打开网站内容页面的情况下阅读支持rss输出的网站内容。网站提供rss输出,有利于让用户发现网站内容的更新。

rss如何工作?
首先您一般需要下载和安装一个rss新闻阅读器,然后从网站提供的聚合新闻目录列表中订阅您感兴趣的新闻栏目的内容。订阅后,您将会及时获得所订阅新闻频道的最新内容。

阅读rss新闻的特点?
1.没有广告或者图片来影响标题或者文章概要的阅读。
2.rss阅读器自动更新你定制的网站内容,保持新闻的及时性。
3.用户可以加入多个定制的rss提要,从多个来源搜集新闻整合 到单个数据流中。


随着网络的普及,越来越多的人习惯通过网络来获取信息、查询资料。虽然各种各样的门户网站纷纷兴起,但在各个网站之间来回穿梭也的确是十分麻烦,搜索引擎可以帮助我们搜索到任何想要找的东西,但查找起来也比较麻烦。现在网络上出现了一种全新的资讯方式,他可以把我们定阅的各种资讯送到我们的桌面上来,不但可以及时了解最新的新闻资讯,而且免去了浏览网站时恼人的网络广告,这种最新的资讯方式被叫做信息聚合,简称rss。
通过rss技术,我们可以把定阅的最新的资讯接收到电脑桌面上,要接收rss信息,使用rss阅读器是最好的方法。当网站内容更新时,rss阅读器就会自动接收,把最新的信息接收到本地电脑桌面上来,同时可以看到最新信息的标题与摘要,点击标题就能够查看全文内容了。自从去年国内“博客”的兴起,使的rss资源渐渐多了起来,同时各大网站也纷纷推出了rss服务,通常只要看到网站上有xml标志,就说明该网站提供rss服务。
feeddemon、看天下网络资讯浏览器 、新浪点点通阅读器、周博通等是常见的rss阅读器。

复制代码 代码如下:

<%
dim rs,newrss
class rss
'*******************输入参数********************
'***********************************************
'setconn 必填 网站使用的connection对象
'setsql 必填 sql查询语句。强烈建议使用在sql语句中使用top关键字
' sql语句中包含的字段[新闻id,标题,内容,时间,静态页名称]
' 注:不要颠倒顺序
' 如果新闻不是生成的静态页,则无最后一项,setpagetype的值则为1
'setwebname 必填 网站名称
'setweburl 必填 网站的地址
'setwebdes 非必填 网站的描述信息
'setpagetype 必填 信息显示页的链接类型 1 为动态页面id 0为静态页面
'setmaxinfo 非必填 强制显示信息的数目,若取数据>setmaxinfo 则显示setmaxinfo条数据。强烈建议使用在sql语句中使用top关键字
'setcontentshow 非必填 信息简介设置。注意:该参数为数组(showcontenttype,showcontentlen)
' showcontenttype [数字类型] 为内容显示方式[参数(0,1)0为按百分比就算显示信息,1为按字数]
' showcontentlen 内容显示的长度 由showcontenttype 决定实际长度
'*****************输出参数********************
'showrss 显示rss
'======================================================
'例如
'set newrss=new rss
' set newrss.setconn=article_conn
' newrss.setsql="select top 30 newsid,title,content,dateandtime,n_fname from article where typeid=1 order by newsid desc"
' newrss.setwebname="测试中"
' newrss.setweburl="//www.jb51.net"
' newrss.setmaxinfo=10
' newrss.setinfourl="//www.jb51.net"
' newrss.setpagetype="0"
' newrss.setcontentshow="1,200"
' newrss.showrss()
'set newrss=nothing
'======================================================
private conn,sql,webname,weburl,webdes,er,maxinfo,i,infourl,pagetype
private showcontenttype,showcontentlen
private allcontent,allcontentlen
private sub class_initialize()
maxinfo=20
'pagetype=1
showcontenttype=0
showcontentlen=20
er=false
end sub
private sub class_terminate()
if isobject(rs) then set rs=nothing
end sub
public property let errmsg(msg)
if er then
response.clear()
response.write(msg)
response.end()
end if
end property
public property let setwebname(webname_)
webname=webname_
end property
public property let setweburl(weburl_)
weburl=weburl_
end property
public property let setwebdes(webdes_)
webdes=webdes_
end property
public property let setinfourl(infourl_)
infourl=infourl_
end property
public property let setpagetype(pagetype_)
pagetype=pagetype_
end property
public property let setmaxinfo(maxinfo_)
maxinfo=maxinfo_
end property
public property let setcontentshow(contentshow_)
dim arrcontentshow
arrcontentshow=split(contentshow_,",")
if ubound(arrcontentshow)<>1 then er=true:errmsg="信息显示参数设置有误!!"
showcontenttype=arrcontentshow(0)
showcontentlen=arrcontentshow(1)
if not isnumeric(showcontenttype) or showcontenttype="" then showcontenttype=0
if not isnumeric(showcontentlen) or showcontentlen="" then
if showcontenttype=0 then showcontentlen=20 else showcontentlen=200
else
if showcontenttype=0 and (showcontentlen>100 or showcontentlen<10) then showcontentlen=20
end if
end property
public property set setconn(conn_)
if typename(conn_)="connection" then
set conn=conn_
else
er=true
errmsg="数据库连接错误"
exit property
end if
end property
public property let setsql(sql_)
sql=sql_
end property
public property get rsshead()
rsshead="<?xml version=""1.0"" encoding=""gb2312"" ?> "
rsshead=rsshead&"<rss>"
rsshead=rsshead&"<channel>"
rsshead=rsshead&"<title>"&webname&"</title>"
rsshead=rsshead&"<link>"&weburl&"</link>"
rsshead=rsshead&"<description>"&webdes&"</description>"
end property
private property get rssbottom()
rssbottom="</channel>"
rssbottom=rssbottom&"</rss>"
end property
public sub showrss()
on error resume next
dim rs
dim showinfourl,showcontent,content
if typename(conn)<>"connection" then er=true:errmsg="connection对象有误"
if sql="" or isnull(sql)="" or isempty(sql)="" then er=true:errmsg="没有可执行的sql语句"
if webname="" or isnull(webname)="" or isempty(webname)="" then er=true:errmsg="请设置rss标题"
if weburl="" or isnull(weburl)="" or isempty(weburl)="" then er=true:errmsg="请设置网站的链接"
if infourl="" or isnull(infourl)="" or isempty(infourl)="" then er=true:errmsg="请设置链接信息"
if pagetype="" or isnull(pagetype)="" or isempty(pagetype)="" then er=true:errmsg="请设置链接类型"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if err then
er=true
errmsg="数据库未能打开<br />请检查您的sql语句是否正确"
exit sub
end if

response.charset = "gb2312"
response.contenttype="text/xml"
response.write(rsshead)
for i =1 to maxinfo
'*****************************
showinfourl=infourl
if showinfourl="" or isnull(showinfourl) or isempty(showinfourl) then
showinfourl="#"
else
if pagetype then showinfourl=showinfourl&rs(0) else showinfourl=showinfourl&rs(4)
end if
'*****************************
allcontent=losehtml(rs(2))
allcontentlen=bytelen(allcontent)
showcontent=int(showcontentlen)
if showcontenttype=0 then showcontent=allcontentlen*showcontent/100
content=server.htmlencode(titleb(allcontent,showcontent))
response.write("<item>")
response.write("<title>")
response.write(rs(1))
response.write("</title>")
response.write("<link>")
response.write(showinfourl)
response.write("</link>")
response.write("<description>")
response.write(content)
response.write("</description>")
response.write("<pubdate>")
response.write(return_rfc822_date(rs(3),"gmt"))
response.write("</pubdate>")
response.write("</item>")
if rs.eof or i>cint(maxinfo) then exit for
rs.movenext
next
response.write(rssbottom)
end sub
function losehtml(contentstr)
dim clstemplosestr,regex
clstemplosestr = cstr(contentstr)
set regex = new regexp
regex.pattern = "<\/*[^<>]*>"
regex.ignorecase = true
regex.global = true
clstemplosestr = regex.replace(clstemplosestr,"")
losehtml = clstemplosestr
end function
function return_rfc822_date(byval mydate, byval timezone)
dim myday, mydays, mymonth, myyear
dim myhours, myminutes, myseconds

mydate = cdate(mydate)
myday = enweekdayname(mydate)
mydays = right("00" & day(mydate),2)
mymonth = enmonthname(mydate)
myyear = year(mydate)
myhours = right("00" & hour(mydate),2)
myminutes = right("00" & minute(mydate),2)
myseconds = right("00" & second(mydate),2)


return_rfc822_date = myday&", "& _
mydays&" "& _
mymonth&" "& _
myyear&" "& _
myhours&":"& _
myminutes&":"& _
myseconds&" "& _
" " & timezone
end function
function enweekdayname(inputdate)
dim result
select case weekday(inputdate,1)
case 1:result="sun"
case 2:result="mon"
case 3:result="tue"
case 4:result="wed"
case 5:result="thu"
case 6:result="fri"
case 7:result="sat"
end select
enweekdayname = result
end function
function enmonthname(inputdate)
dim result
select case month(inputdate)
case 1:result="jan"
case 2:result="feb"
case 3:result="mar"
case 4:result="apr"
case 5:result="may"
case 6:result="jun"
case 7:result="jul"
case 8:result="aug"
case 9:result="sep"
case 10:result="oct"
case 11:result="nov"
case 12:result="dec"
end select
enmonthname = result
end function
function titleb(str,strlen)
dim bstrlen
bstrlen=strlen
if isempty(str) or isnull(str) or str="" then
titleb=str
exit function
else
dim l,t,c,i
l=len(str)
t=0

for i=1 to l
c=abs(asc(mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if

if t>=bstrlen then
titleb=left(str,i)
exit for
else
titleb=str&""
end if
next
end if
end function
function bytelen(str)
dim lenstr,lentemp,i
lenstr=0
lentemp=len(str)
dim strtemp
for i=1 to lentemp
strtemp=asc(mid(str,i,1))
if strtemp>255 or strtemp<=0 then
lenstr=lenstr+2
else
lenstr=lenstr+1
end if
next
bytelen=lenstr
end function
end class
%>

1

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网