2016-07-31 98 views
0

我想從某個網站獲取一些國家名稱。該網站URL以https開頭,所以我無法取消數據。請給我一些解決方案。如何從https網站取消數據

這裏是我的代碼:

$curl = curl_init('https://testing.co/india'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 
$page = curl_exec($curl); 
if (curl_errno($curl)) {`enter code here` 
    echo 'Scraper error: ' . curl_error($curl); 
    exit; 
} 
curl_close($curl); 
$regex = '/<a class="startup-link">(.*?)<\/a>/s'; 
if (preg_match($regex, $page, $list)) 
    echo $list[0]; 
else 
    print "Not found"; 

得到這個錯誤:Scraper error: SSL certificate problem: unable to get local issuer certificate

+1

請通過:http://stackoverflow.com/questions/31162706/how-to-scrape-a-ssl-or-https -url –

回答

-1

使用

curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false) 
0

,今天我要解決這個問題,我才知道這件事。

參見。以下是正在爲我工​​作的代碼。

// Set so curl_exec returns the result instead of outputting it.<br/> 
$url = "https://www.google.co.in/?gws_rd=ssl";<br/> 
$ch = curl_init();<br/> 
curl_setopt($ch, CURLOPT_URL, $url);<br/><br/> 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br/> 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<br/> 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);<br/> 
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "GeoTrustGlobalCA.crt"); 
    <br/> 
// Get the response and close the channel.<br/> 
$response = curl_exec($ch);<br/> 
$link = fopen("data.txt","w+");<br/> 
fputs($link,$response);<br/> 
fclose($link);<br/> 
curl_close($ch);<br/> 

您對這個有合格證書.. 在Mozilla Firefox離開網站的網址,handside你得到一個信息圖標。然後點擊安全選項卡,然後找到查看證書。點擊詳細信息選項卡。 請參閱證書層次結構部分。點擊最上面的標籤,看下面有一個選項作爲EXPORT。導出該證書並將CA證書保存到您選擇的位置,確保選擇X.509證書(PEM)作爲保存類型/格式。

例如
curl_setopt($ ch,CURLOPT_CAINFO,getcwd()。「GeoTrustGlobalCA.crt」);

現在保存並運行。你將得到的數據..