E
E
EvgMul2017-02-27 00:51:42
PHP
EvgMul, 2017-02-27 00:51:42

How to download all css/js/page images using curl?

Hello. I have the following problem.
It is required using cURL to get the page and display it on your domain. The problem is that the page also has various css, js and pictures files. To be honest, I don’t fully understand how cURL works, but in the developer’s console I see that he tries to load all these additional files, but gets a 404 error, because the paths to these files are relative and cURL takes my domain as the main domain , not the donor site.
Please tell me if there is a solution to this problem and if so, how can it be solved?
Current script code:

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://site.com');
    //curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_COOKIEJAR, realpath("cookie.txt"));
  curl_setopt($ch, CURLOPT_COOKIEFILE, realpath("cookie.txt"));
    curl_exec($ch);
    curl_close($ch);

Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2017-02-27
@EvgMul

curl is not a browser, it does exactly what it should - loads the page and does not know about all the additional files.
therefore, you yourself need to look for them on the page and download them yourself or change the links to absolute ones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question