1

我已经尝试过使用 import.io 上的网络爬虫服务的示例 Owl 数据集,但是当我尝试将其与他们的示例 PHP 集成时,我不断得到“NULL”作为结果。

$userGuid = "MY_USER_ID";
$apiKey = "MY_API_KEY";

// Issues a query request to import.io
function query($connectorGuid, $input, $userGuid, $apiKey) {

    $url = "https://query.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Content-Type: application/json",
        "import-io-client: import.io PHP client",
        "import-io-client-version: 2.0.0"
    ));
    curl_setopt($ch, CURLOPT_POSTFIELDS,  json_encode(array("input" => $input)));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $result = curl_exec($ch);
    curl_close($ch);

    return json_decode($result);
}

// Query for tile owltest
echo "Test";
$result = query("71e57dbc-9996-4fa3-8715-c564a347d002", array(
  "webpage/url" => "http://owlkingdom.com/",
), $userGuid, $apiKey, false);
var_dump($result);

我已经在几台服务器上尝试过,但没有任何乐趣。反正我没有修改代码。如果我将 URL 弹出到浏览器中,我会以 JSON 格式返回给我的数据集 OK。

其他人对示例脚本有任何问题吗?

4

1 回答 1

1

改变了

$url = "https://query.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);

$url = "http://query.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);

这解决了这个问题。如果需要安全连接,我相信您还可以修改 curl 选项以接受站点的 SSL 证书。

于 2014-10-24T13:27:02.730 回答