PHP 中的完整实现如下所示:
<?php
$domain = "example.com"; // Enter your domain here.
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&"
. "q=link:".$domain;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $domain);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
$urls = array();
foreach($json->responseData->results as $result) // Loop through the objects in the result
$urls[] = $result->unescapedUrl; // and add the URL to the array.
?>
Run Code Online (Sandbox Code Playgroud)
基本上,您在顶部编辑域变量,它将$urls用链接到域的未转义 URL 填充数组。
编辑:我已编辑链接以返回 8 个结果。如需更多信息,您必须解析页面并使用 start 参数循环遍历它们。有关详细信息,请参阅类参考。