thibauts / node-google-search-scraper

Google search scraper with captcha solving support
MIT License
89 stars 37 forks source link

Captcha decoding not working #3

Open developeron29 opened 8 years ago

developeron29 commented 8 years ago

customSolver not working

On creating a server and sending the image to the browser and later posting the result to be sent through the callback returns


/Users/../.../check1.js:77
  if(err) throw err;
          ^

Error: Captcha decoding failed

with customSolver as

app.post('/api/bears', function(req, res) {

            console.log(req.body.user.name);

            var id = null, err = null; 

            callback(err, id, req.body.user.name);

            res.end();
        });
thibauts commented 8 years ago

Your customsolver should take imageData and return the text contained in the captcha image. I don't understand what your are doing with your API endpoint.

developeron29 commented 8 years ago

Yep, Absolutely, Right

That's what i'm trying to do, by rendering the image to the browser, entering the text into the input box and sending it to the captcha solver

Thanks for the help!

The whole code:


var scraper = require('google-search-scraper');
  var application_root = __dirname,path = require("path");
//var DeathByCaptcha = require('deathbycaptcha');
var http = require('http')
  , fs = require('fs');
var express    = require('express');        // call express
var app = express.createServer();     // set our port
app.configure(function () {
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(application_root, "public")));
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

//var dbc = new DeathByCaptcha('username', 'password');
var customSolver = {
  solve: function(imageData, callback) {
    // Do something with image data, like displaying it to the user
    // id is used by BDC to allow reporting solving errors and can be safely ignored here
    console.log(imageData);
//var router = express.Router();              // get an instance of the express Router

     // if (err) throw err; // Fail if the file can't be read.
    app.get('/api', function(req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write('<html><body><img src="data:image/jpeg;base64,')
        res.write(new Buffer(imageData).toString('base64'));
        res.write('"/>');
        res.write('<form method="post" action="/api/bears/">');
        res.write('<input type="text" name="user[name]">');
        res.write('<input type="submit" value="Submit">');
        res.write('</form>');
        res.end('</body></html>'); 
    });

        app.post('/api/bears', function(req, res) {

            console.log(req.body.user.name);

            var id = null, err = null; 

            callback(err, id, req.body.user.name);

            res.end();
        });

  }
};
app.listen(4242);

var options = {
  query: 'site:edu "information theory"',
  age: 'y', // less than a year,
  solver: customSolver
};

scraper.search(options, function(err, url) {
  // This is called for each result
  if(err) throw err;
  console.log(url)
});
thibauts commented 8 years ago

If your code correctly returns the right decoded text to the callback then google probably changed its way to handle the captcha solution submission. It's very unexpected as seemingly the first part doesn't change, or your code wouldn't display a correct image.

If you want to make it work you'll have to investigate by navigating to google in your browser, solving the captcha by hand, looking at the form submission in the traffic and modifying the code so it behaves in the same way.

developeron29 commented 8 years ago

Great, Thanks! I might have found the problem: On doing the search on browser instead, google was returning two captchas one after the other So, after getting the first one correct, it shows one more captcha.

developeron29 commented 8 years ago

Yes, After returning the captcha text, maybe Google recognizes that the user is unauthorized to access the page and i get this html: , with statusCode 403

localhost_4242_api_ _and_ayushnarula_ayushs-macbook-pro_ _-zsh_ _80x17_and_testsearch_js_ _state-of-mobile-web__drive-admin__developeron29_github_io error_403__forbidden___1_ _and_index_html_ _state-of-mobile-web__drive-admin__developeron29_github_io

I'll update you, if i find a solution, Thanks!

DanDaDaDanDan commented 7 years ago

Were you able to find a solution? Asking as I'm not having much luck with DBC as is.

edenfisher commented 7 years ago

any solution guys?

goldgavin commented 7 years ago

captchaId changed, use post instead of get, then it will return redirect url then get it again

var captchaId = $('input[name=q]').attr('value');
session.post({
              uri: baseUrl + '/sorry/' + formAction,
              qs: {
                q: captchaId,
                captcha: solution,
                continue: continueUrl
              }
            }, function(err, res) { // get the res.headers.location if statusCode is 302})