Problems with jQuery load | CORS

Asked

Viewed 510 times

1

I am trying to "capture" some information contained on a third-party page directly on a page I am currently coding on.

I am using jquery to do this, because I only want one or two information that is on this page, in case I want to take only the price and name of the product that is on the American site.com and upload directly to my site. For when they update it, my website automatically updates it without me having to codify it all the time.

I’m trying to use this line:

$( "#conteudo" ).load( "http://www.americanas.com/exemplo-produto #preco" );

I am student still, more so as I know until now the error if gives due CORS, cross-origin Resource sharing because of the following error:

Failed to load http://americanas.com/exemplo-produto: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://127.0.0.1:3000' is therefore not allowed access.

As far as I know so far I can’t solve this problem, because as far as I know I would have to ask permission for them to "include me" on the page I’m trying to order?

Is there any other option for me to succeed in this case?

Thank you very much!

  • CORS only releases on the same server. Another option would be to create a Crawler.

  • 1

    The above user is correct, you could use a Chrome extension that "frees" this or disable the verification flags on Chrome. However, it does not solve your problem for the production, see this link https://answall.com/questions/256548/problema-com-cors-usando-ionic-e-lumen/261211#261211 Ideal for you to make a Crawler, see this example: https://scrapy.org/ Then the information is saved in your database and passed to the end user.

  • Thank you very much!! I will do this this afternoon, thank you for your time! ;)

1 answer

0

This happens because the page you are trying to get information, has a kind of lock to prevent this action so that it is not possible to access it from an external server.

  • Thank you Fábio! I know that, but as a student I still end up getting some things, but thank you very much for your time! ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.