我正在编写一个抓取脚本。它可以在大多数网站上工作,但我无法访问特定的SSL网站。
下面是我的代码:if (!extension_loaded('openssl')){
// not occurring
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.chase.com/');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
if($result === false)
{
$err = curl_error($ch);
//$err = SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
}
$result
总是FALSE
,它显示这个错误消息:
SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
但是它可以在其他有SSL的网站上工作。我还检查了phpinfo()
, cURL和OpenSSL是活跃的。我正在使用WAMP,有什么想法吗?
需要设置Useragent。我测试了有没有一个,它解决了这个问题。Chase似乎希望在请求中提供UA。
所以加上这个:
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US)');
我通过使用以下PHP库解决了这个问题。
https://github.com/rmccue/Requests [在Linux服务器上使用这个库代码,可能它不能在xampp或wamp上工作]