教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php抓取https内容的方法

php抓取https内容的方法

发布时间:2014-11-16   编辑:jiaochengji.com
php抓取https内容,直接使用file_get_contents,会报错。

直接使用file_get_contents,会报错。
$url = (https://xxx.com");
file_get_contents($url);

错误:
Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3

用curl的方式没有问题:
 

复制代码 代码如下:
<?php
$url = (https://xxx.com);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
print_r($result);
?>

重点是这两句:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

您可能感兴趣的文章:
php抓取https内容的方法
php file_get_contents抓取https地址报错的解决办法
php file_get_contents函数抓取页面信息的代码
python怎么获取js动态加载的数据
Python3爬虫入门:pyspider 框架介绍
PHP实现抓取HTTPS内容的方法和错误处理
Python爬虫进阶之Robots协议
PHP 抓取内容中图片并下载保存的代码
Python3爬虫入门:Robots协议
php 获取远程网页内容简单函数

关键词: php抓取  数据抓取  网站数据抓取   
[关闭]
~ ~