Using jQuery to get HTML from another site: maybe? Legal?

I am trying to get HTML code from a webpage that is not in the same domain. The html text is analyzed and summarizes the recipe (recipe name, main ingredients, number of steps) found on this page from which the HTML code was.

The user can then click the link and go to this web page outside the domain to view the recipe.

I am aware of the "same outcome" policy, but does this apply if the HTML code from the web page is outside the internal domain? I imagine this is exactly the same as getting XML, so it is legal and allowed, right?

Is there a way to get HTML text / code from a domain outside my internal domain?

The use of Javascript and JQuery is to limit the number of queries and server storage by executing user queries for each recipe and parsing client-side HTML. This stops the bottlenecks on the server side, and also means that I do not need to go through the server and delete old obsolete recipes.

I am open to solutions / suggestions in any programming language or API, etc.

+6
source share
5 answers

What you are trying to do cannot be done using any AJAX library. Cross-domain browser policies will not allow you to do this.

But you can do this with a combination of php (or any other server language) and AJAX. Create a php script as follows:

<?php $url=$_POST['url']; if($url!="") echo file_get_contents($url); ?> 

Let's say the name of the script is fetch.php . Now you can send an AJAX call from your jQuery code to this fetch.php , and it will select the HTML code for you.

+8
source

No, this will not work on client-side JavaScript. The browser prevents this for security reasons. You will need to make ajax calls on a local script server (e.g. PHP), which will then retrieve the content (e.g. via cURL) and return the required HTML.

+3
source

To add something to the answers already received, I can say that html not intended to be used as a β€œas a service” data transfer method. To do this, there is XML or JSON open through SOAP or REST .

In your scenario, the best approach that I can come up with in mind both technical and legal aspects is to use an iframe to display external content and a link to the source of the iframe content, including the external link as you already do.

You can still try the server-side approach to get the remote html, but again, and not a clean way to do this, of course, is not very good practice and maybe not legal.

If the content author wants to be reused outside of his site, he can express this intention by submitting unformatted content through a service or RSS / Atom .

+2
source

The same thing is happening. try this code and you will encounter a security error

 $.get("other web page site", {}, function(content){ $("#receipe").html(content) }, "html") 

btw, you are likely to violate copyright law, so be careful :-)

+1
source

I'm not sure if this seems like a clean JavaScript solution, but: http://developer.yahoo.com/yql/ can help you with what you are looking for.

0
source

Source: https://habr.com/ru/post/903738/


All Articles