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?
|
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
|
|
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?
|