2013-04-28 3 views
1

내가 구글에서 키워드의 위치를 ​​얻기 위해 약간의 스크립트를 가지고있다 :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; } 
    } 
} 

거의 잘 작동합니다. 일부 키워드의 경우 wokr을 사용하지 않지만 verry는 잘 작동합니다. 예를 들어 :

  • 키워드 : 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이 작동하지 않습니까?

답변

1

이 솔루션은 매우 간단하다 :

만 쿼리 URL :

http://www.google.com/search?as_q='.$keywords.'&hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&num=100&start=$start&btnG=Google+Search&as_epq=&as_oq=&as_eq=&lr=&as_ft=i&as_filetype=&as_qdr=all&as_occt=any&as_dt=i&as_sitesearch=&as_rights=&safe=images  
관련 문제