[ad_1]
I have a robot
And through CURL, I can get the download link from the Freepik site
But there is a problem
After receiving 3 or 4 download links
The CSRF value changes and the robot stops
Can I get the CSRF parameter via a cookie or some other method?
Or suggest another way to do this
I also changed the user agent, but the problem was not resolved
$csrf = c06cdeb93e405ee73b8da754b3c7d4a1;
$useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36";
$cookie="cookies/freepik.txt";
$url = "https://www.freepik.com/xhr/download-url/$id";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json, text/plain, */*', "User-Agent:$useragent", 'x-requested-with:XMLHttpRequest', "x-csrf-token:$csrf"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$res = json_decode($result);
if($res->success) {
# $name = $res->filename;
$download = $res->url;
$file = downloadFile($download);
[ad_2]