codemanki / cloudscraper

--DEPRECATED -- 🛑 🛑 Node.js library to bypass cloudflare's anti-ddos page
MIT License
599 stars 139 forks source link

captcha problem after new update #295

Closed SFx2018 closed 4 years ago

SFx2018 commented 4 years ago

Hello, I was using this code: https://github.com/codemanki/cloudscraper/issues/62#issuecomment-482880177

to resolve captcha with anti-captcha service on ogusers forum since new update of this library

I tried to change url by adding $("#challenge-form").attr('action'); this variable to url, and changed method to POST but doesn't work.

Please help (:

drdokk commented 4 years ago

You should try this for captcha solving : https://github.com/codemanki/cloudscraper/blob/master/docs/examples/solve-recaptcha.js

SFx2018 commented 4 years ago

could someone help me to fix current code, I don't want to re-work whole code to use solve-recaptcha.js

function gotError(error) {
    if (error instanceof CaptchaError) {
        log(`Prompted for ReCAPTCHA. Solving...`);

        const { options } = error;
        const body = error.response.body.toString(`utf8`);
        const $ = cheerio.load(body);
        const sitekey = $(`[data-sitekey]`).data(`sitekey`);
        const query = {};

        $(`#challenge-form`).serializeArray().forEach((input) => query[input.name] = input.value);
        solveReCAPTCHA(options.uri, sitekey, (error, captcharesponse) => {
            if (error) {
                gotError(error);
                return;
            }

            query[`g-recaptcha-response`] = captcharesponse;
            cf({
                "uri": `https://ogusers.com/cdn-cgi/l/chk_captcha`,
                "qs": query,
                "followAllRedirects": true,
                "method": `GET`
            }).then(() => cf(options).then(options.cb).catch(gotError)).catch(gotError);
        });
        return;
    }

    let errmsg;
    if (error.response && error.response.body && error.response.body.includes(`Board Message`)) {
        const $ = cheerio.load(error.response.body);
        errmsg = $(`col_row`).text().trim();
    }

    log(`Something went wrong: ${errmsg ? errmsg : `${error.name || error.message}${error.statusCode ? ` (${error.statusCode})` : ``}`}${error.options ? ` @ '${error.options.uri}'` : ``}`);
}
codemanki commented 4 years ago

Closing as this is not related to the cloudscraper.