Google からキーワードの位置を取得するための小さなスクリプトがあります。
if($_POST) {
//print('post');
// Clean the post data and make usable
$domain = filter_var($_POST['domain'], FILTER_SANITIZE_STRING);
$keywords = filter_var($_POST['keywords'], FILTER_SANITIZE_STRING);
// Remove begining http and trailing /
$domain = substr($domain, 0, 7) == 'http://' ? substr($domain, 7) : $domain;
$domain = substr($domain, -1) == '/' ? substr_replace($domain, '', -1) : $domain;
// Replace spaces with +
$keywords = strstr($keywords, ' ') ? str_replace(' ', '+', $keywords) : $keywords;
$keywords = urlencode($keywords);
// Grab the Google page using the chosen keywords
$html = new DOMDocument();
@$html->loadHtmlFile('http://www.google.hu/search?q='.$keywords.'&num=100');
print('http://www.google.hu/search?q='.$keywords.'&num=100');
$xpath = new DOMXPath($html);
// Store the domains to nodes
$nodes = $xpath->query('//div[1]/cite');
// Loop through the nodes to look for our domain
$hit = 2;
foreach ($nodes as $n){
// echo '<div style="font-size:0.7em">'.$n->nodeValue.'<br /></div>'; // Show all links
if (strstr($n->nodeValue, $domain)) {
$message = $i; $hit = 1;
}
else { ++$i; }
}
}
それはほとんどうまくいきます。一部のキーワードでは機能しませんが、他のキーワードでは非常にうまく機能します。例えば:
- キーワード:
ingyen társkereső
- ドメイン:
http://ingyen-tarskereso.hu
これはクエリの URL です。http://www.google.hu/search?q=ingyen%2Btarskereso&num=100
うまくいきません。しかし、キーワードingyenes fájlmegosztás
とドメインboxy.tigyisolutions.hu
を使用すると、機能します。
何が悪いのか分かりますか?
たぶんnum100が機能していませんか?