title: Crawling Google Search with PHP
body: <p>I trying to get my head around how to fetch Google search results with PHP or JavaScript. I know it has been possible before but now I can't find a way.</p>
  
  <p>I am trying to duplicate (somewhat) the functionality of<br>
   <a href="http://www.getupdated.se/sokmotoroptimering/seo-verktyg/kolla-ranking/" rel="nofollow">http://www.getupdated.se/sokmotoroptimering/seo-verktyg/kolla-ranking/</a></p>
  
  <p>But really the core issue I want to solve is just to get the search result via PHP or JavaScript,the rest i can figure out.</p>
  
  <p>Fetching the results using file_get_contents() or cURL doesn't seem to work.</p>
  
  <p>Example: </p>
  
  <pre><code>$ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, 'http://www.google.se/#hl=sv&amp;q=dogs');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $result = curl_exec($ch);
  curl_close($ch);
  echo '&lt;pre&gt;';
  var_dump($result);
  echo '&lt;/pre&gt;';
  </code></pre>
  
  <p>Results:</p>
  
  <blockquote>
    <p>string(219) "302 Moved The document has moved here."</p>
  </blockquote>
  
  <p>So, with some Googling i found <a href="http://code.google.com/apis/customsearch/v1/overview.html" rel="nofollow">http://code.google.com/apis/customsearch/v1/overview.html</a> but that seems to only work for generating a custom search for one or more websites.
  It seem to require a "Custom Search Engine" cx-parameter passed.</p>
  
  <p>So anyway, any idea?</p>