java - RSS Parser returns 403 -


i'm new java , given assignment xml parsing. have done dom , on sax. that's why i'm using sax parser parsing rss feed. working on files when try parse online rss feed, returns error 403. haven't tried parsing same site on dom because laptop slow takes me 5 minutes open file.

thanks help.

public class newshandler extends defaulthandler {     private string url = "http://tomasinoweb.org/feed/rss";     private boolean indescription = false;      private string[] descs = new string[11];      int = 0;          public void processfeed() {              try {              saxparserfactory factory =               saxparserfactory.newinstance();              saxparser parser = factory.newsaxparser();              xmlreader reader = parser.getxmlreader();              reader.setcontenthandler(this);              inputstream inputstream = new url(url).openstream();               reader.parse(new inputsource(inputstream));               } catch (exception e) { e.printstacktrace(); }         }         public void startelement(string uri, string localname, string qname,              attributes attributes) throws saxexception {             if(qname.equals("description")) indescription = true;          }          public void characters(char ch[], int start, int length) {              string chars = new string(ch).substring(start, start + length);              if(indescription) descs[i] = chars;          }          public void endelement(string uri, string localname, string qname) throws saxexception {             if(qname.equals("description")) {                            indescription = false;                           i++;                      }         }          public string getdesc(int index) { return descs[index]; }          public static void main(string[] args) {             newshandler nh = new newshandler();             nh.processfeed();              for(int i=0; i<10; i++) {                 system.out.println(nh.getdesc(i));             }          } } 

solution:

instead of using string url = "url", used url url = new url("url") , urlconnection con = url.openconnection() , con.addrequestproperty("user-agent", user-agent string);


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -