在PHP中抓取安全页面HTTPS


scraping a secure page https in php

我试图用curl抓取一个安全页面(https),比如谷歌

但我似乎没有从我的爬虫中获取任何数据

PHP函数

function getDOM($url){
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_RANGE, '0-100');
   $content = curl_exec($ch);
   curl_close($ch);
   echo $url."<br>";
   echo $content;

   $dom = new simple_html_dom();
   $dom->load($content);
   if($dom){
      return $dom;
   }
   return null;
}
getDOM("https://www.google.co.uk/search?sugexp=chrome,mod=14&sourceid=chrome&ie=UTF-8&q=crawling%20https#hl=en&gs_nf=1&pq=site:stackoverflow.com%20crawling%20https%20php&cp=6&gs_id=s&xhr=t&q=stackoverflow&pf=p&sclient=psy-ab&oq=stacko&aq=0&aqi=g4&aql=&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=8baefeb740f734a5&biw=1280&bih=685");

我能做些什么来抓取https,因为我似乎在普通页面上没有这个问题

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

将此添加到您的代码中。这将允许任何证书通过,因此它应该适合您的使用(但通常不是一个好主意)。