JAXBContext jc = JAXBContext.newInstance(StackOverflowXPathMap.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); URL xmlURL = new URL("http://stackoverflow.com/feeds"); URLConnection conn = xmlURL.openConnection(); conn.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"); conn.connect(); InputStream xml = xmlURL.openStream(); StackOverflowXPathMap stackOverflowXPathMap = (StackOverflowXPathMap) unmarshaller.unmarshal(xml); System.out.println(stackOverflowXPathMap.getAuthor()); xml.close(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(stackOverflowXPathMap, System.out);
I`m trying to parse RSS from stackowerflow, but I have some troubles. Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: http://stackoverflow.com/feeds
No comments:
Post a Comment