Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to get RSS link from html source code. I used Jsoup java library to find rss link. I wrote a small piece of code to get RSS links, but unfortunately it is not working for all the websites. Below is my code

String url = "http://www.smashingmagazine.com/"; // not working
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("link[type=application/rss+xml]");

if (links.size() > 0) {
    String rss_url = links.get(0).attr("href").toString();
} else {
    // RSS url not found
}

The above code is not working for all the websites. Please solve my problem. (I am trying to find RSS 2.0 links)

Thank You

share|improve this question
Why don't you go the the smashing magzine's RSS feed and parse it using a java based RSS parser like Rome. The above process can be repeated pretty much with any site that provide RSS feeds. – RanRag May 27 '12 at 7:19
No the url is not static. User can give any website url, i need to find the rss url and parse it. – user911236 May 27 '12 at 7:26
If you observe your webpage it doesn't have application/rss+xml instead it has application/atom+xml – RanRag May 27 '12 at 7:32
Thank you RanRag. But in this url dtscinema.com if you see the source code there application/rss+xml is present still i am not getting rss url. – user911236 May 27 '12 at 7:37
Are you sure the site is dtscinema.com b'coz when I am trying to open it from here it seems the domain has expired. – RanRag May 27 '12 at 7:42
show 3 more comments

1 Answer

the answer is :

String url = "http://www.smashingmagazine.com/"; // not working
Document doc = Jsoup.connect(url).get();

Elements links = doc.select("link[type=application/rss+xml]");

if (links.size() > 0) {
    String rss_url = links.get(0).attr("abs:href").toString();
} else {....
    // RSS url not found
}

I hope it will be ok for you. It works with .attr(*"abs:*href")

Ertu

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.