Asp產生RSS的類_給網站加上RSS第1/2頁

來源:互聯網
上載者:User

什麼是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="http://www.jb51.net"
' NewRss.SetMaxInfo=10
' NewRss.SetInfourl="http://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
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.