php:curl
Fonction cURL téléchargement page web
- curl.php
function get_web_page( $url )
{
$user_agent='Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0';
$options = array(
CURLOPT_CUSTOMREQUEST =>"GET",
CURLOPT_USERAGENT => $user_agent,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_MAXREDIRS => 3,
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$curlerror = curl_error( $ch );
$WebPage = curl_getinfo( $ch );
curl_close( $ch );
$WebPage['curl_error'] = $curlerror;
$WebPage['content'] = $content;
return $WebPage;
}
$result = get_web_page('https://www.wikipedia.org/');
echo $result['content'];
php/curl.txt · Dernière modification: 2017-10-26 08:17 de mitsu