用asp给网站添加rss聚合功能
时间:2007-11-05 19:08:00
为你的网站,博客等添加rss聚合功能,给出rss.asp和rss.xml
两种的聚合代码
看过的朋友可帮忙顶哦,这些代码都是第一次发的,外面很多要不就是很复杂,看不懂,
要不就是不能用的,这里我修改了一下,写的时候也已经尽量简洁明了
以经测试,支持大部分聚合阅读器
rss.asp格式的
下面代码保存为rss.asp
<!--#include file="conn.asp"-->
<%
strURL = "http://" & request.servervariables("server_name") & _
left(request.servervariables("script_name"),len(request.servervariables("SCRIPT_NAME"))-len("/rss.asp")) //中的/rss.asp为你的该文件名
sql="select top 100 * from [表名] order by id desc" //根据自己实际修改,top 100 为最新100条,自己修改,同时可以增加查询条件,如where xxx=1....
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
response.contenttype="text/xml"
response.write "<?xml version=""1.0"" encoding=""gb2312"" ?>" & vbcrlf
response.write "<rss version=""2.0"">" & vbcrlf
response.write "<channel>" & vbcrlf
response.write "<title>xxx.com RSS feed</title>" & vbcrlf
response.write "<link>" & strURL & "</link>" & vbcrlf
response.write "<language>zh-cn</language>" & vbcrlf
response.write "<copyright>An RSS feed for xxx.comcopyright>" & vbcrlf
while not rs.eof
response.write "<item>" & vbcrlf
response.write "<title><![CDATA[" & rs("title") & "]]></title>" & vbcrlf
response.write "<link>"&strURL&"/xxxx.asp?Id="&rs("id")&"</link>" & vbcrlf
response.write "<description><![CDATA[" & rs("主题字段") & "<br />" & rs("内容字段") & "<br /><br />]]></description>" & vbcrlf
response.write "<pubDate>" & return_RFC822_Date(rs("时间字段"),"GMT") & "</pubDate>" & vbcrlf
response.write "</item>" & vbcrlf
rs.movenext
wend
response.write "</channel>" & vbcrlf
response.write "</rss>" & vbcrlf
rs.close
set rs=nothing
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
%>
rss.xml格式的
<!--#include file="conn.asp"-->
<%
strURL = "http://" & request.servervariables("SERVER_NAME") & _
left(request.servervariables("SCRIPT_NAME"),len(request.servervariables("SCRIPT_NAME"))-len("/rss.asp"))
dim foolcat,js
set js = server.CreateObject("ADODB.RecordSet")
sql = "select * from [表名] order by id asc"
set js = conn.execute (sql)
foolcat = foolcat + "<?xml version=""1.0"" encoding=""UTF-8"" ?>"
foolcat = foolcat + "<rss version=""2.0"">"
foolcat = foolcat + "<channel>"
foolcat = foolcat + "<title>xxx.com XML feed</title>"
foolcat = foolcat + "<link>" & strURL & "</link>"
foolcat = foolcat + "<language>zh-cn</language>"
foolcat = foolcat + "<copyright>An XML feed for xxx.com</copyright>"
do until js.eof
foolcat = foolcat + "<item>"
foolcat = foolcat + "<title><![CDATA[" & rs("主题字段") & "]]></title>"
foolcat = foolcat + "<description><![CDATA[" & rs("主题字段") & "<br />" & rs("内容字段") & "<br /><br />]]></description>"
foolcat = foolcat + "<link>" & strURL & "/xxx.asp?Id="&rs("id字段")&"</link>"
foolcat = foolcat + "<pubDate>" & rs("时间字段") & "</pubDate>"
foolcat = foolcat + "</item>"
js.movenext
loop
js.close
set js = nothing
foolcat = foolcat + "</channel>"
foolcat = foolcat + "</rss>"
foolcat = "" + foolcat + ""
foolcat = "" & foolcat & ""
FolderPath = Server.MapPath("/")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(FolderPath&"\rss.xml")
fout.writeLine foolcat
fout.close
set fout = nothing
conn.close
set conn = nothing
%>
标签:rss,聚合
0
投稿
猜你喜欢
详细介绍mysql中limit与offset的用法
2024-01-21 10:52:48
CentOS7.2虚拟机上安装MySQL 5.6.32的教程
2024-01-23 07:30:59
ASP.NET页面间的传值的几种方法
2024-05-11 09:26:52
python 实现客户端与服务端的通信
2023-11-19 01:28:33
sql server 视图作用
2009-01-05 13:53:00
Python Selenium 之数据驱动测试的实现
2021-12-16 22:45:27
mysql中的跨库关联查询方法
2024-01-25 22:48:06
互联网科技大佬推荐的12本必读书籍
2022-08-23 12:56:38
FireFox浏览器使用Javascript上传大文件
2023-11-17 09:49:27
Golang 实现Redis 协议解析器的解决方案
2024-02-19 20:09:36
Mysql数据库手动及定时备份步骤
2024-01-27 10:43:15
CSS滤镜示范(filter)附源代码(静态滤镜)
2008-05-18 12:42:00
基于python的mysql复制工具详解
2023-06-24 01:08:28
使用window.name解决跨域问题
2008-09-04 12:10:00
Python selenium 父子、兄弟、相邻节点定位方式详解
2023-07-03 06:19:09
mysql远程跨库联合查询的示例
2024-01-13 23:09:10
3个比较好用的asp检查函数
2007-09-24 13:25:00
zabbix监控MySQL主从状态的方法详解
2024-01-22 00:29:24
MySQL sql_mode的使用详解
2024-01-16 00:13:59
Python学习之字符串常用方法总结
2021-12-19 02:19:46