MSN Space Parser (ASP.NET)

This code is really useful if you want to parse a MSN Space Blog and publish it into a web site.
I used it for my VolleyBall team site: http://www.usomvolley.com

Private Function get_tag(ByVal tag As String,
ByVal source As String) As String
Dim start_pos, end_pos As Integer
start_pos = source.IndexOf("<" & tag & ">") + Len(tag) + 2
end_pos = source.IndexOf("</" & tag & ">")
Return source.Substring(start_pos, end_pos - start_pos)
End Function

Function retag(ByVal text As String) As String
text = text.Replace("&lt;", "<")
text = text.Replace("&gt;", ">")
text = text.Replace("&amp;", "&")
Return text
End Function

Private Function GetPage(ByVal URL As String) As String
' Create a new webrequest to the mentioned URL.
Dim myWebRequest As WebRequest = WebRequest.Create(URL)

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse
Dim myStream As New StreamReader(myWebResponse.GetResponseStream, Encoding.UTF8)
Return myStream.ReadToEnd
End Function

Function ParseMSNSpace(ByVal User As String)
Dim Space_Page As String
Dim Post, PostType, PostTitle, PostLink, PostDesc, PostDate, PostCommentsNum, PostCommentsURL As String
Dim Posts_Array() As String
Dim i As Integer
Space_Page = GetPage("http://spaces.msn.com/members/" & User & "/feed.rss")
Posts_Array = Split(Space_Page, "<item>", -1, CompareMethod.Text)

For i = 1 To Posts_Array.Length - 1
Post = Posts_Array(i)
PostType = get_tag("msn:type", Post)
If PostType = "blogentry" Then
PostTitle = retag(get_tag("title", Post))
PostLink = get_tag("link", Post)
PostDesc = retag(get_tag("description", Post))
PostDate = get_tag("pubDate", Post)
PostCommentsNum = get_tag("slash:comments", Post)
PostCommentsURL = get_tag("comments", Post)
Response.Write("<font size='4'><a href = '" & PostLink & ">" & PostTitle & "</a></font><br />")
Response.Write("<font color='#777777'>" & PostDate & "</font><br /><br />")
Response.Write(PostDesc)
Response.Write("<br /><br />")
End If
Next
End Function
Share on Google Plus

About Vittorio Pavesi

    Blogger Comment
    Facebook Comment

0 commenti: