Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Java rss grabber  (Read 1631 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: April 26, 2009, 08:03:51 AM »

One of the many sourcecodes i found that i made a long time ago.

Code
GeSHi (java):
  1. /*--------------------------------------------------------------------------
  2. RssGrabber class
  3.  *****************
  4. By: HappyFace http://www.engineeringserver.com
  5. Contact: info [@] engineeringserver.com
  6. Version: unknown
  7. Last updated: 01/August/2008
  8. "*****************
  9. Note: a demo that grabs and shows rss feeds
  10. //----------------------------------------------------------------------*/
  11. import java.io.IOException;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.util.Collection;
  15. import java.util.Iterator;
  16.  
  17. import com.sun.cnpi.rss.elements.Item;
  18. import com.sun.cnpi.rss.elements.Rss;
  19. import com.sun.cnpi.rss.parser.RssParser;
  20. import com.sun.cnpi.rss.parser.RssParserException;
  21. import com.sun.cnpi.rss.parser.RssParserFactory;
  22.  
  23. public class RssGrabber {
  24. RssParser parser;
  25. Rss rss;
  26.  
  27. public static void main(String[] args){
  28. RssGrabber RG = new RssGrabber();
  29. try {
  30. RG.parser = RssParserFactory.createDefault();
  31. RG.rss = RG.parser.parse(new URL("http://www.engineeringserver.com/blog/feed"));
  32. RG.showBlogPost();
  33. } catch (RssParserException e) {
  34. e.printStackTrace();
  35. } catch (MalformedURLException e) {
  36. e.printStackTrace();
  37. } catch (IOException e) {
  38. e.printStackTrace();
  39. }
  40. }
  41.  
  42. public void showBlogPost(){
  43. Collection items = rss.getChannel().getItems();
  44. Iterator i = items.iterator();
  45. while(i.hasNext()){
  46. Item item = (Item)i.next();
  47. System.out.println("Title: " + item.getTitle());
  48. System.out.println("Link: " + item.getLink());
  49. System.out.println("Description: " + item.getDescription());
  50. }
  51. }
  52. }
  53.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here