title: Google search results with php
body: <p>I'm using the following php script to get search results from Google.</p>
  
  <pre><code>include("simple_html_dom.php");
  include("random-user-agent.php");
  
  
  $query = 'facebook';
  
  $curl = curl_init();  
  curl_setopt($curl, CURLOPT_URL, 'http://www.google.com/search?q='.$query.'');   
  #curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
  curl_setopt($curl, CURLOPT_USERAGENT,random_user_agent());
  $str = curl_exec($curl);   
  curl_close($curl);   
  
  $html= str_get_html($str);  
  
  $i = 0;
  foreach($html-&gt;find('li[class=g]') as $element) {
      foreach($element-&gt;find('h3') as $item) 
      {
          $title[$i] = ''.$item-&gt;plaintext.'' ;
      }
         $i++;
  }
  print_r($title);
  </code></pre>
  
  <p>When this script runs in a cronjob (with 5 sec sleep) I receive a warning from Google and have to fill in a captcha (obvious). I always thought that using curl and a random user agent can avoid this. What is the correct solution?</p>