sostart
9/13/2018 - 9:16 AM

file_get_contents 抓取

file_get_contents 抓取

$url = 'http://baidu.com';

$opts  = array(
   'http' =>array(
     'method' => 'GET',
     'header' => "Connection: keep-alive\r\n".
                 "Upgrade-Insecure-Requests: 1\r\n".
                 "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\r\n".
                 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n".
                 "Accept-Encoding: gzip, deflate\r\n".
                 "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8\r\n",
     'content' => http_build_query([])
   )
);

$rs = file_get_contents('compress.zlib://'.$url, false, stream_context_create($opts));

echo '<xmp>'.$rs.'</xmp>';