Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Most sites has textbox for Comments if you like sometimes when you watch video then bellow the page you can go and put your comments there and able to see other people's comments It and up look like conversation some people even able to through those comments responding others or commenting based to other comments.

So what I am trying to do is to get those comments given the RSS FEED URL for that particular site. or any other way that can help me to achieve my goal.

What I have tried:

Java
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;

import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

public class mainclass{
	
	@SuppressWarnings({ "rawtypes" })
	public static void main(String [] args){
		
	try{
		
		URL url = new URL("http://mybroadband.co.za/news/tag/mtn/feed");
		HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
		
		
		httpURLConnection.setRequestProperty("User-Agent", "Mozilla/5.0");
		
		
		SyndFeedInput input = new SyndFeedInput();
		SyndFeed feed = null;
	try {
		feed = input.build(new XmlReader(httpURLConnection));
	} catch (IllegalArgumentException | FeedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    	//List entries =(List) feed.getEntries();
    	Iterator itEntries = feed.getEntries().iterator();
    
 while(itEntries.hasNext()){
	 	SyndEntry entry = (SyndEntry)itEntries.next();	

	 	//System.out.print(entry.getTitle()+"\n");
	 	//System.out.println("Description");
	 	System.out.print("TITLE: "+entry.getTitle() +"\n");
	 	System.out.print("Discription:");
	 	System.out.print(entry.getDescription() +"\n");
 
    }
    
	}
	catch(MalformedURLException e){		
		e.printStackTrace();		
	}
    catch(IOException e){		
		e.printStackTrace();				
	}
	
	}
}
Posted
Updated 8-Nov-22 8:18am
v2
Comments
Richard Deeming 19-Jul-16 10:00am    
How you do this, and whether you can do this, will vary from site to site.

Looking at the source of the feed you've posted, you'll see elements that look like:
<wfw:commentRss>http://....html/feed</wfw:commentRss>
where wfw is the prefix for the namespace "http://wellformedweb.org/CommentAPI/".

You'll need to extract those links, and load the comments from them. Unfortunately, I'm not familiar with the classes you're using, so I can't tell you how you would do that.

Having checked a couple of the links, they don't seem to return any data. I'm not sure whether that means there are no comments, or that the comment feed doesn't work. If it's the latter, then you won't be able to read the comments from the RSS feed.
Member 12642822 19-Jul-16 10:27am    
thank you vary much. May you please give me an examples for that , you can use any language or classes that you are familiar with
thanks

1 solution

Use the following regular expression pattern:

"\<wfw\:commentRss\>(.*)\<\/wfw\:commentRss\>"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900