We open the list of pages through curl specified in the file
The script in php. There is a url list file. It is required to open them all automatically.
$ txt=“
https://sait.ru/page1/
https://sait.ru/page2/
// etc.
“;
// Get the link
$ a1=explode(“ n“,$ txt);
$ a1=array_unique($ a1);
foreach($ a1 as $ url) {
$ ch = curl_init($ url);
// Create the file name from the URL
$ path_parts = pathinfo($ url);
try{
if( ! ( $ ch = curl_init($ url) ) )
throw new Exception(‘Curl init failed’);
$ options = [[
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FAILONERROR => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60,
CURLOPT_SSL_VERIFYPEER => thirty,
CURLOPT_SSL_VERIFYHOST => thirty,
CURLOPT_HEADER => 0,
CURLOPT_HTTPHEADER => [[
‘User-Agent’ => ‘Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_13) AppleWebKit / 604.1.38 (KHTML, like Gecko) Version / 11.0 Safari / 604.1.38’,
]
];
curl_setopt_array($ ch, $ options);
$ fp = fopen(‘pages /’.$ path_parts[[‘basename’], ‘wb’);
curl_setopt($ ch, CURLOPT_FILE, $ fp);
curl_exec($ ch);
curl_close($ ch);
fclose($ fp);
} catch(Exception $ e){
echo $ e->getMessage();
}
}
Hey. You are on my site. I am a developer. Here I share my best practices and knowledge. Ask in the comments if you don’t understand something or write if you have something to add.