3

我正在尝试使用 curl抓取安全页面(https),例如google

但我似乎没有从我的爬虫那里得到任何数据

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,因为我似乎对普通页面没有这个问题

4

1 回答 1

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

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

于 2012-06-16T17:57:54.800 回答