php file_get_contents抓取

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 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>';

以上是关于php file_get_contents抓取的主要内容,如果未能解决你的问题,请参考以下文章

php中抓取网页内容的代码

php抓取一个页面的图片

php 文件操作之抓取网站图片

php抓取页面的几种方法详解

PHP 抓取 HTTPS 网站内容

php 怎么设置带着请求头请求网页