rss阅读器怎么用:用vb.net开发RSS阅读器
用vb.net开发RSS阅读器
下面是源代码
没有太多注释
都比较简单嘛!
Imports .Xml
Imports .Threading
Public Class Form1Class Form1
Inherits .Windows.Forms.Form
#Region " Windows 窗体设计器生成代码 "
Friend WithEvents ListBox1 As .Windows.Forms.ListBox
Friend WithEvents Button1 As .Windows.Forms.Button
Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
Friend WithEvents Label1 As .Windows.Forms.Label
Friend WithEvents Label2 As .Windows.Forms.Label
Friend WithEvents TextBox1 As .Windows.Forms.TextBox
Friend WithEvents StatusBar1 As .Windows.Forms.StatusBar
Friend WithEvents Label4 As .Windows.Forms.Label
Me.Button1.Text = "读取"
Me.Label1.Text = "网站WebSite:"
Me.Label2.Text = "描述:"
Me.TextBox1.Text = "http://www.cnblogs.com/aowind/Rss.aspx"
Me.StatusBar1.Text = "StatusBar1"
Me.Label4.Text = "RSS地址:"
#End Region
Private thread As thread '定义个线程
Private Sub loadrssSub loadrss '读取RSS文件并取出内容标题过程
StatusBar1.Text = "正在读取" & TextBox1.Text & "并效验"
Me.loadxmltocache(TextBox1.Text)
StatusBar1.Text = "正在读取相关网站WebSite信息"
Me.loadtitle
StatusBar1.Text = "正在读取相RSS内容项"
Me.loaditem
StatusBar1.Text = "完成"
End Sub
Private Sub Button1_ClickSub Button1_Click(ByVal sender As .Object, ByVal
e As .EventArgs) Handles Button1.Click
Try
thread = New Thread(AddressOf loadrss)
thread.Start
Catch ex As Exception
MsgBox(ex.)
End Try
End Sub
Private Sub Form1_LoadSub Form1_Load(ByVal sender As .Object, ByVal e As
.EventArgs) Handles MyBase.Load
AxWebBrowser1.Width = Me.Width
StatusBar1.Text = "就绪"
End Sub
Private Sub loadxmltocacheSub loadxmltocache(ByVal URL As String)
'读取RSS文件并存放在本地以供操作
Dim xmldocument As New XmlDocument
xmldocument.Load(URL)
xmldocument.Save(Application.StartupPath & "~doc.xml")
End Sub
Private Sub loadtitleSub loadtitle
'从本地文件中进行操作读取RSS中有关网站WebSite信息
Dim xmlDocument As New XmlDocument
xmlDocument.Load(Application.StartupPath & "~doc.xml")
Dim mynodelist As XmlNodeList
mynodelist = xmlDocument.SelectNodes("/rss/channel")
Label1.Text = "网站WebSite:" & Trim(mynodelist(0).Item("title").InnerText)
Label2.Text = "描述:" & Trim(mynodelist(0).Item("description").InnerText)
End Sub
Private Sub loaditemSub loaditem
'从本地文件中进行操作读取RSS中内容标题及作者
Dim xmlDocument As New XmlDocument
xmlDocument.Load(Application.StartupPath & "~doc.xml")
Dim mynodelist As XmlNodeList
mynodelist = xmlDocument.SelectNodes("/rss/channel/item")
ListBox1.Items.Clear
Dim i As Integer
For i = 0 To mynodelist.Count - 1
ListBox1.Items.Add("[" &
Trim(mynodelist(i).Item("dc:creator").InnerText) & "]" &
Trim(mynodelist(i).Item("title").InnerText))
Next
End Sub
Private Sub ListBox1_SelectedIndexChangedSub ListBox1_SelectedIndexChanged(ByVal
sender As .Object, ByVal e As .EventArgs) Handles
ListBox1.SelectedIndexChanged
thread = New Thread(AddressOf loadhtml)
thread.Start
End Sub
Private Sub loadhtmlSub loadhtml
'读取RSS中对应文件内容并存到临时文件后显示
Dim xmlDocument As New XmlDocument
xmlDocument.Load(Application.StartupPath & "~doc.xml")
Dim mynodelist As XmlNodeList
mynodelist = xmlDocument.SelectNodes("/rss/channel/item")
Dim i As Integer
Dim j As Boolean
Dim content As String
StatusBar1.Text = "正在读取文章内容"
For i = 0 To mynodelist.Count - 1
If ListBox1.SelectedItem = "[" &
Trim(mynodelist(i).Item("dc:creator").InnerText) & "]" &
Trim(mynodelist(i).Item("title").InnerText) Then
content = content & "<html><head><meta http-equiv='content-type'
content='text/html;char=UTF-8'></head><body>"
content = content & "<table width='100%' height='80'
bgcolor='#eeeeee'><tr><td><b>标题:</b><a href='"
content = content & Trim(mynodelist(i).Item("link").InnerText)
content = content & "' target='_blank'>"
content = content & Trim(mynodelist(i).Item("title").InnerText)
content = content & "</a><br><b>作者:</b>"
content = content & Trim(mynodelist(i).Item("dc:creator").InnerText)
content = content & "</tb></tr></table>"
content = content &
formatHtml(mynodelist(i).Item("description").InnerText)
content = content & "</body></html>"
j = SaveTextFile(Application.StartupPath & "~temp.html", content)
AxWebBrowser1.Navigate(Application.StartupPath & "~temp.html")
Exit For
End If
Next
StatusBar1.Text = "完成"
End Sub
'写文件过程
Function SaveTextFileFunction SaveTextFile(ByVal FilePath As String, ByVal
FileContent As String) As Boolean
Dim sw As .IO.StreamWriter
Try
sw = New .IO.StreamWriter(FilePath, False)
sw.Write(FileContent)
Return True
Catch e As Exception
Return False
Finally
If Not sw Is Nothing Then sw.Close
End Try
End Function
'从地址里取网址
Private Function formatURLFunction formatURL(ByVal str As String) As String
Dim sStr As String
Dim i As Integer
Dim j As Integer
For i = 1 To Len(str)
sStr = sStr & Mid(str, i, 1)
If Mid(str, i, 1) = "/" Then
j 1
End If
If j = 3 Then Exit For
Next
Return sStr
End Function
'将内容里相对图片地址改成绝对地址
Private Function formatHtmlFunction formatHtml(ByVal str As String) As String
Return Replace(str, "src=" & Chr(34) & "/", "src =" & Chr(34) &
formatURL(TextBox1.Text))
End Function
End Class
延伸阅读
最新评论