Exemplo n.º 1
0
 public function solveCaptcha(CaptchaSolver $solver)
 {
     // once request is made, a new LAST_CAPTCHA_URL must be generated for it to work
     if (!$this->last_captcha_url) {
         return false;
     }
     $captcha_html = $this->client->get($this->last_captcha_url, array('exceptions' => false));
     // TODO: check to make sure we're really on a captcha page
     // extract form values for submission
     if (preg_match('/<img src="([^"]+)"/', $captcha_html, $matches)) {
         // assumine PROTOCOL and HOST stay the same
         $img_url = "http://ipv4.google.com/" . htmlspecialchars_decode($matches[1]);
         // extract additional data from image query string
         $query = parse_url($img_url, PHP_URL_QUERY);
         $vars = array();
         parse_str($query, $vars);
         // download captcha image
         $response = $this->client->get($img_url, array('exceptions' => false));
         // get raw bytes
         $img_bytes = $response->getBody();
         // read text from image
         $text = $solver->solve($img_bytes);
         // form data
         $data = array('q' => $vars['q'], 'continue' => $vars['continue'], 'id' => $vars['id'], 'captcha' => $text, 'submit' => 'Submit');
         // submit form... hopefully this will set a cookie that will let you search again without throwing captcha
         // GOOGLE_ABUSE_EXEMPTION lasts 3 hours
         $response = $this->client->get('http://ipv4.google.com/sorry/CaptchaRedirect?' . http_build_query($data), array('exceptions' => false));
         return $response->getStatusCode() == 200;
     }
     return false;
 }
Exemplo n.º 2
0
 public function solveCaptcha(CaptchaSolver $solver)
 {
     $continue = rawurlencode('http://www.' . $this->preferences['google_domain'] . '/search?q=gmail');
     $captcha_html = $this->client->get('http://ipv4.google.com/sorry/IndexRedirect?continue=' . $continue, array('exceptions' => false));
     // extract form values for submission
     if (preg_match('/image\\?id=(\\d+)&amp;/', $captcha_html, $matches) && preg_match('/name="continue" value="([^"]+)/', $captcha_html, $matches2)) {
         $id = $matches[1];
         $img_url = "http://ipv4.google.com/sorry/image?id={$id}&hl=en";
         $continue = $matches2[1];
         // download captcha image
         $response = $this->client->get($img_url, array('exceptions' => false));
         $img_bytes = $response->getBody();
         // read text from image
         $text = $solver->solve($img_bytes);
         $vars = array('continue' => $continue, 'id' => $id, 'captcha' => $text, 'submit' => 'Submit');
         // submit form... hopefully this will set a cookie that will let you search again without throwing captcha
         // GOOGLE_ABUSE_EXEMPTION lasts 3 hours
         $response = $this->client->get('http://ipv4.google.com/sorry/CaptchaRedirect?' . http_build_query($vars), array('exceptions' => false));
         //echo $response->getBody();
         return $response->getStatusCode() == 200;
     }
     return false;
 }