我怎样才能卷曲深度爬行?
Posted
技术标签:
【中文标题】我怎样才能卷曲深度爬行?【英文标题】:How can I curl deepcrawl? 【发布时间】:2019-03-02 11:27:37 【问题描述】:我的 Deepcrawl 抓取只给出空值。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.deepcrawl.com/accounts/00000/projects/195334/crawls/1306396/reports/thin_pages_basic");
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token:Private'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output2 = curl_exec ($ch);
curl_close ($ch);
$results = json_decode($server_output2);
要创建会话,您首先需要手动生成 API 密钥。这是可以在 API 访问页面中生成的键/值对。当您单击 Generate New API Key 时,将显示一个带有 API Key Value 的弹出窗口,在 Active Keys 表中您可以找到 API Key ID。然后通过基本身份验证在 POST 调用中将其发送到会话路由。
curl -X POST -u '123:abcdef' https://api.deepcrawl.com/sessions
"token":"abcdef123",
"_user_href":"/users/example-user",
...
从会话调用返回的令牌然后作为 X-Auth-Token 标头传递给所有 API 调用:
curl -X GET -H 'X-Auth-Token:' https://api.deepcrawl.com/accounts/1/projects
有人可以进一步解释一下 deepcrawl 的身份验证吗?我怎样才能只使用X-Auth-Token
来卷曲它。对不起,我的英语不好。谢谢
【问题讨论】:
echo curl_error();
告诉你什么?
@delboy1978uk curl_error(): 提供的资源不是有效的 cURL 句柄资源
对不起! curl_error($ch)
同一个伙伴。不知道为什么。
在curl_close($ch)
行之前完成
【参考方案1】:
CURL 有时可能很棘手。
当我遇到 CURL 问题时,我首先尝试在命令行上做同样的事情,在这种情况下它运行良好,因此我们可以拒绝 API 或 CURL 上存在任何类型的问题,因此我们必须假设问题出在php 调用。
当你得到一个 NULL 时,很可能在 curl 处理程序上设置了一个错误,你只需要寻找它并将它带到屏幕上:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.deepcrawl.com/accounts/00000/projects/195334/crawls/1306396/reports/thin_pages_basic");
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token:Private'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output2 = curl_exec ($ch);
if (curl_errno($ch))
print curl_error($ch);
die();
// or whatever you might want to do with this error
curl_close ($ch);
$results = json_decode($server_output2);
在这种情况下,错误是:
SSL 证书问题:无法获取本地颁发者证书
Here你可以看到如何解决这个问题,只需要像这样在你的php.ini中添加一个有效的CA证书(在示例中使用cacert):
1) 从https://curl.haxx.se/ca/cacert.pem下载最新的cacert.pem
2) 将以下行添加到 php.ini(如果这是共享主机并且您无权访问 php.ini,那么您可以将其添加到 public_html 中的 .user.ini)
curl.cainfo="/path/to/downloaded/cacert.pem"
【讨论】:
以上是关于我怎样才能卷曲深度爬行?的主要内容,如果未能解决你的问题,请参考以下文章
Windows 10怎样不利用第三方付费软件实现对C盘的深度清理