Check if URL is indexed by Google using PHP

一笑奈何 提交于 2019-12-19 23:23:01

问题


I would like to know if it's possible to check if URL is indexed by Google using PHP.

Is this against their ToS?


回答1:


You can read here (relevant citation below) for an answer to the ToS part of this. Basically, without an API key and their permission, it probably is not a good idea. However, due to the volume they handle, you might be able to get away with it if you're not making TONS of requests.

PageRank checking is something else that people often try to do, but they don't place as much weight on this merit (rumor has it), and the older style API keys are really hard to find.

Don't use unauthorized computer programs to submit pages, check rankings, etc. Such programs consume computing resources and violate our Terms of Service. Google does not recommend the use of products such as WebPosition Gold™ that send automatic or programmatic queries to Google.




回答2:


To do so without an API is against the TOS. For low volume, you can:

// CHECK IF PAGE IS IN GOOGLE INDEX
$domain = 'stackexchange.com';
if (strstr(file_get_contents("http://www.google.com/search?q=site:$domain"), 'did not match any documents')) {
  // Page is not in the index
  print 'No Go!';
}
else {
  print 'All Good!';
}
exit;



回答3:


Well, not explicitly. But you can check every page view using:

$agent = $_SERVER['HTTP_USER_AGENT'];

if (strstr($agent, 'googlebot')){

  // tell the database that google has crawled this page.
}



回答4:


For polish language you should try check between UTF-8 and ISO-8859-2 like this:

$encAry = array('ISO-8859-2', 'UTF-8');
$contentEncoding = mb_detect_encoding( $content, $encAry );
$googleSearchResult = mb_convert_encoding($content, 'UTF-8', $contentEncoding);

Works for me.



来源:https://stackoverflow.com/questions/4391972/check-if-url-is-indexed-by-google-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!