Parse image URLs in remote HTML as JSON

I want to create a URL similar to the LinkedIn and Facebook link, where do you paste the URL and delete the deleted content using the available image scroller?

LinkedIn example

Basically, my idea is that I need to pull HTML from a remote URL using my XML server side XMLHTTP script. Then I want to be able to check any images (for a certain width / height - for example, no transpixels are loaded.)

Is it possible to load all the remote HTML as escapable JSON, and then use jQuery to check for suitable images that need to be inserted into the scroller?

+4
source share
1 answer

You cannot do this directly because of the same origin policy, you can use an iframe to retrieve a web page, but you cannot read it. you need a simple script server that will be a proxy. If you use php and allow open URLs as files, you can use this:

<?php if (isset($_GET['url'])) { echo json_encode(get_file_contents($_GET['url'])); } 

and then using ajax you can fetch pages using urls and you can use jquery as a parser.

 $.getJSON('fetch.php', {url: "http://google.pl"}, function(html) { $(html).find('img'); }); 
0
source

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


All Articles