Ravi
Ravi

Reputation: 3200

Screen scraping a data from a Web Site

I am building my first chrome extension and trying to display some forex rates on my google chrome extension.But I am finding myself struck with cross domain is not allowed by Access-Control-Allow-Origin problem.Is There a way to scrap a data from cross domain web page using jquery.For your kind info the third party webpage I am referring does not support webservice :(

Please find below the code I am trying to use in my chrome extension to scrap the current forex rate.Please help . Thanks in advance

$.ajax({
 url: "http://someCrossDomain.forexrate.html",
 dataType: 'text', 
 success: function(data) { 
 console.log($("h2:first").text()); 
} });

Upvotes: 0

Views: 692

Answers (3)

Boris Smus
Boris Smus

Reputation: 8472

Make sure you're setting host permissions in your extension manifest:

Upvotes: 1

Marius Kjeldahl
Marius Kjeldahl

Reputation: 6824

For a packaged app, you can do ajax requests without running into the cross-site access restrictions. I'm not 100% sure that it is needed, but if you are still having trouble, then make sure you add http://*/ to your permission section in the manifest (or restrict it further if you only need to make calls to certain sites). For hosted applications, you can not do cross-site requests without either a cooperating server (which specifically allows it), or using a proxy on your own server.

Upvotes: 1

PseudoNinja
PseudoNinja

Reputation: 2856

To get around the cross-site the best option (IMHO) is to write a web-service call to handle the request, then call it from your jQuery call. But if you can't write a web service to handle in a bit bigger pickle.

Upvotes: 0

Related Questions