【问题标题】:can't scrape data - from httpswebsite无法抓取数据 - 来自 httpswebsite
【发布时间】:2016-07-31 10:10:02
【问题描述】:

我正在尝试从其中一个网站获取一些国家/地区名称。该网站 URL 以 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

【问题讨论】:

标签: php web-scraping


【解决方案1】:

今天我正在解决这个问题,我开始了解它。

看。下面是对我有用的代码。

// 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/>

您已通过此证书.. 在网站 URL 的 Mozilla firefox 左侧,您会看到一个信息图标。然后单击安全选项卡,然后找到查看证书。单击详细信息选项卡。 请参阅证书层次结构部分。单击最上面的标签并在下面看到一个选项作为导出。导出该证书并将 CA 证书保存到您选择的位置,确保选择 X.509 证书 (PEM) 作为保存类型/格式。

例如
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "GeoTrustGlobalCA.crt");

现在保存并运行..你会得到数据..

【讨论】:

    【解决方案2】:

    使用

    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false)
    

    【讨论】:

      猜你喜欢
      • 2019-09-03
      • 2019-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 2017-06-18
      相关资源
      最近更新 更多