我想创建自己的使用PHP进行反向链接计算的工具。是否有任何api to fetech反向链接的数据
答案 0 :(得分:4)
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.
?>
基本上,您在顶部编辑域变量,它会在$urls
数组中填充链接到域的未转义URL。
编辑:我编辑了链接以返回8个结果。更多信息,您必须解析页面并使用start参数循环遍历它们。有关详细信息,请参阅Class Reference。
答案 1 :(得分:1)
使用前缀为link:
的网址运行Google搜索 - 例如link:www.mydomain.com
。
虽然Google确实在其网站站长工具区域(more info)中提供了更具体的反向链接概述,但我不确定它们是否为其提供了外部API。
答案 2 :(得分:1)
因为问题是“如何在PHP代码中使用?”我假设你想要在服务器端进行处理而不是在客户端进行ajax处理。因此,请使用Google URL链接:hack与curl结合使用 http://php.net/manual/en/book.curl.php
答案 3 :(得分:1)
还有一个PHP类,有更多选项,您可以使用:http://code.google.com/p/seostats/
答案 4 :(得分:1)
function load_content ($url, $auth = true,$auth_param) {
$curl = curl_init();
$uagent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
if ($auth){
curl_setopt($curl, CURLOPT_USERPWD,$auth_param);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $uagent);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 3);
$content = curl_exec($curl);
//$header = curl_getinfo($curl);
curl_close($curl);
$res['msg'] = "";//$header;
$res['content'] = $content;
return $res;
}
function google_indexed($url){
$html = load_content ($url,false,"");
return $html;
}
示例:
<?php
$domain = "google.com";
$indexed["google"] = google_indexed("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:$domain");
http://alex-kurilov.blogspot.com/2012/09/backlink-checker-google-php-example.html
答案 5 :(得分:0)
查找页面的外部链接:(外部反向链接)
<?php
$url = "any url";
$result_in_html = file_get_contents("http://www.google.com/search?q=link:{$url}");
if (preg_match('/Results .*? of about (.*?) from/sim', $result_in_html, $regs))
{
$indexed_pages = trim(strip_tags($regs[1])); //use strip_tags to remove bold tags
echo ucwords($domain_name) . ' Has <u>' . $indexed_pages . '</u>external links to page';
} elseif (preg_match('/About (.*?) results/sim', $result_in_html, $regs))
{
$indexed_pages = trim(strip_tags($regs[1])); //use strip_tags to remove bold tags
echo ucwords($domain_name) . ' Has <u>' . $indexed_pages . '</u> external links to page';
} else
{
echo ucwords($domain_name) . ' Has Not Been Indexed @ Google.com!';
}
?>
找到内部反向链接:
<?php
$url = "any url";
$result_in_html = file_get_contents("http://www.google.com/search?q=site:{$url}");
if (preg_match('/Results .*? of about (.*?) from/sim', $result_in_html, $regs))
{
$indexed_pages = trim(strip_tags($regs[1])); //use strip_tags to remove bold tags
echo ucwords($domain_name) . ' Has <u>' . $indexed_pages . '</u> internal links to page';
} elseif (preg_match('/About (.*?) results/sim', $result_in_html, $regs))
{
$indexed_pages = trim(strip_tags($regs[1])); //use strip_tags to remove bold tags
echo ucwords($domain_name) . ' Has <u>' . $indexed_pages . '</u> internal links to page';
} else
{
echo ucwords($domain_name) . ' Has Not Been Indexed @ Google.com!';
}
?>