YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Looking for sample .NET code on accessing Craigslist RSS feed. Options
Geek
#1 Posted : Saturday, January 08, 2011 12:08:25 PM
Rank: Newbie


Groups: Registered

Joined: 7/10/2009
Posts: 6
Location: Southern California
I am trying to write a utility for myself to access a Craigslist RSS feed. Anyone have a sample piece of code that does this?
barrob326
#2 Posted : Tuesday, January 11, 2011 10:21:22 AM
Rank: Administration


Groups: Registered

Joined: 7/10/2009
Posts: 50
Location: So California
Here is a sample for you, there are references in this code to local object on a .NET form.

Code:
   
Public Sub ProcessLocation()


        Dim XMLDoc As System.Xml.XmlDocument = New System.Xml.XmlDocument
        Dim nTable As NameTable = XMLDoc.NameTable
        Dim nsManager As XmlNamespaceManager = New XmlNamespaceManager(nTable)
        Dim sDescription As String
        Dim sTitle As String
        Dim sCost As String
        Dim sURL As String
        Dim sLocation As String
        Dim sAdDate As String
        Dim dAdDate As Date
        Dim iLocationStart As Integer
        Dim iLocationEnd As Integer
        Dim iCostStart As Integer
        Dim iCostEnd As Integer

        'All outputs are being written to a multi line text box Me.tbStatus.Text
        Try

            'Example http://newyork.craigslist.org/cpg/index.rss
            XMLDoc.Load("http://newyork.craigslist.org/cpg/index.rss")

            'Reset before we process.
            sTitle = ""
            sURL = ""
            sDescription = ""


            nsManager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
            nsManager.AddNamespace("item", "http://purl.org/rss/1.0/")
            nsManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/")
            Dim XMLItems As System.Xml.XmlNodeList = XMLDoc.DocumentElement.SelectNodes("//rdf:RDF/item:item", nsManager)


            For Each currentItem As Xml.XmlNode In XMLItems

                ' Parse
                sAdDate = currentItem.SelectSingleNode("dc:date", nsManager).InnerText
                If IsDate(sAdDate) Then
                    dAdDate = CDate(sAdDate)
                Else
                    dAdDate = Now()
                End If
                Me.tbStatus.Text &= "Date: " & currentItem.SelectSingleNode("dc:date", nsManager).InnerText & Environment.NewLine

                ' get the title and the link
                Me.tbStatus.Text &= "Title: " & currentItem.SelectSingleNode("item:title", nsManager).InnerText & " - "
                Me.tbStatus.Text &= currentItem.SelectSingleNode("item:link", nsManager).InnerText & Environment.NewLine

                sURL = currentItem.SelectSingleNode("item:link", nsManager).InnerText

                sTitle = currentItem.SelectSingleNode("item:title", nsManager).InnerText
                iLocationStart = InStr(sTitle, "(") + 1
                iLocationEnd = InStr(sTitle, ")")
                iCostStart = InStr(sTitle, "$") + 1
                iCostEnd = Len(sTitle)

                ' get the location
                If iLocationEnd = 0 Or iLocationStart Or iLocationStart > iLocationEnd = 0 Then
                    Me.tbStatus.Text &= "Location:" & Me.tbLocation.Text & Environment.NewLine
                    sLocation = Me.tbLocation.Text
                Else
                    Me.tbStatus.Text &= "Location:" & Mid(sTitle, iLocationStart, iLocationEnd - iLocationStart) & Environment.NewLine
                    sLocation = Mid(sTitle, iLocationStart, iLocationEnd - iLocationStart)
                End If

                ' get the cost
                If iCostStart = 0 Or iCostEnd = 0 Then
                    sCost = "0"
                Else
                    sCost = Mid(sTitle, iCostStart, (iCostEnd + 1) - iCostStart) & Environment.NewLine
                    If Not IsNumeric(sCost) Then sCost = 0
                End If

                ' Clean the description of breaks and other special characters
                sDescription = currentItem.SelectSingleNode("item:description", nsManager).InnerText
                sDescription = sDescription.Replace("\r\n<br>", "")
                sDescription = sDescription.Replace("<br>", "")

                Me.tbStatus.Text &= "Cost: $" & sCost & Environment.NewLine

                ' get the description
                Me.tbStatus.Text &= "Description: " & sDescription & Environment.NewLine & Environment.NewLine


                Me.tbStatus.Refresh()
            Next


            Me.tbStatus.Text &= Me.tbLocation.Text & " Complete" & Environment.NewLine
            Me.tbStatus.Text &= "With " & Format$(iCurrentItem) & " Processed" & Environment.NewLine


        Catch ex As Exception
            MsgBox("Error while processing " & Me.tbLocation.Text & ":" & Err.Description)
            Me.tbStatus.Text &= "Title: " & sTitle & Environment.NewLine
            Me.tbStatus.Text &= sURL & Environment.NewLine
            Me.tbStatus.Text &= sDescription & Environment.NewLine
        End Try
    End Sub
Please submit any questions or comments through my website.

http://www.qualitysoftwaredesign.com
Sean
#3 Posted : Monday, January 24, 2011 1:57:30 PM
Rank: Newbie

Groups: Registered

Joined: 8/7/2009
Posts: 8
Location: Wa
When I use this, Craigslist only returns the latest 100 entries. Is there a way to specify more?
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.104 seconds.