views:

56

answers:

6

Hi all,

I'd like to do the following: grab news from several sites, parse their content using jQuery selectors and show them on one page.

How could this be done with jQuery?

Thanks.

+1  A: 

It can't with pure jQuery or JavaScript because you can't fetch content from domains different from the one the script is running from. This is a security measure to prevent Cross Site Scripting

But see a possible solution here: http://stackoverflow.com/questions/1240546/cross-site-scriptingxss

lasseespeholt
Yup. Exception: JSONP data. For anything else, you need a server side proxy script of some sort.
Pekka
+1  A: 

Unless your news is coming from sites that explicitly provide a mechanism for fetching content along the lines of what you want, you can't do this from the client (the browser, that is). You can fetch the content from your server, however, and then hand it over to your client in as raw a state as you like.

Pointy
+3  A: 

For security reason's JavaScript (and thus jQuery) AJAX methods can only retrieve data from URL's on the same domain as your site.

There are some work-around's however. You could use a server-side script to download remote content for you - think of it like a proxy. Alternatively you could look into JSONP, but the remote site needs to provide it.

Justin Ethier
+1  A: 
DMin
+1  A: 

Contrary to other replies, script block sources are not blocked from cross domain access, so if you dynamically add a script block to the header of your page and have the resultant output from the site created as a callback (wrap it in a function call basically, and handle taht function in your own code) then you can access content on other domains - the flip side is that you need the site to present you the data in a callback, otherwise it doesnt work.

Moo
A: 

if the websites you are trying to grab the news from supports rss feed then you can use jquery plugins like jFeed to retrieve the rss and you can then just display it on your own website.

although, i would recommend you setup a webservice (in asp.net, php, etc) that gathers rss or scrape meta tags in the websites you want and then use jquery.get() to retrieve all news

Mouhannad