codemanki / cloudscraper

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

How to set cookies #207

Closed lidorlevi156 closed 5 years ago

lidorlevi156 commented 5 years ago

Its not bypassing for me Cloudflare 5 seconds, i dont know why i use this code:

  var options = {
    method: 'GET',
    url:'http://someurl/',
    proxy: 'http://' + proxies[proxy]
  };
  cloudscraper(options).then(console.log);

in loop and it drag a lot of errors and some success, but most errors, its not even waiting 5 seconds its log the error on the console in one second.

ghost commented 5 years ago

Hi @lidorlevi156, I can't really tell what the problem is based on the information you've provided. For all I know, something is wrong in your code. For example if your proxies variable was undefined at some point, that could match what you've described.

If I'm assuming it's not a bug in your code, I still need to know the error message(s), preferably the URL(s), and/or the response content.

Regarding "waiting 5 seconds", there is not any need to wait 5 seconds before reporting a CAPTCHA, etc. In a lot of cases, these errors are valid and meant to be handled by the user.

I'd like to help you find a solution. Please provide more information.

lidorlevi156 commented 5 years ago

Hello @pro-src , its saying error: captcha always, in everysite that i try to attack that have 5SEC its throw errors. No matter which site, this is problem I am sure and my proxies working well and not undefined. There is are errors:

{ errorType: 1 } { errorType: 3, error: 'Error occurred during evaluation: Illegal return statement' }

one time type 1, other time 3 and 'Error occurred during evaluation: Illegal return statement' How should I fix it?

Thank you very much :)

lidorlevi156 commented 5 years ago

Update: On some sites when I send requests to "HTTP" and not to "HTTPS" its bypassing the 5 seconds in some requests, on other part of sites its doesn't.

ghost commented 5 years ago

@lidorlevi156 some site owners may have CAPTCHA always on for specific paths. I'm unable to reproduce this without a URL but the error doesn't seem quite right. Are you using the latest version of Cloudscraper ^4.0.0??? Based on what you're telling me, I don't think this is a problem with Cloudscraper since to the best of my knowledge Cloudflare has not updated their challenge. I double checked before replying...

I recommend that you remove node_modules, reinstall, and log the version, console.log(require('cloudscraper/package.json').version).

Also see #208 where somebody else mistakenly thought that CF had updated their challenge.

ghost commented 5 years ago

@lidorlevi156 if you haven't already, test your proxy in a web browser. It's possible that the proxy server is using SSL ciphers that aren't common to web browsers: https://github.com/VeNoMouS/cloudflare-scrape-js2py/issues/28#issuecomment-487000582

Since the proxy is making the connection to Cloudflare on your behalf... If you get a response, that doesn't rule out the proxy as a possible cause.

The proxy could...

Does it work when not using a proxy? Does it work in the web browser when the web browser is configured to use the proxy? Did you check to see that the browser was actually using the proxy (IP check)? Etc. Etc....

lidorlevi156 commented 5 years ago

@pro-src Thank you again for good answer, I checked it out and it was the reCaptcha. By the way, can you help how to use cookies on this? I want to use cookies in this great libary but don't know how to set them good in loop. Note: Checked it and User-Agent is setted but dont randomize by the libary, it one User-Agent.

ghost commented 5 years ago

Cloudscraper uses https://www.npmjs.com/package/request which in turn uses https://www.npmjs.com/package/tough-cookie for cookie management. You'll need to refer to the documentation of those respective libraries.

You can access the cookie jar from the defaults: cloudscraper.defaultParams.jar Or use your own:

var tough = require('tough-cookie');
var cookiejar = new tough.CookieJar();
var cloudscraper = require('cloudscraper').defaults({ jar: cookiejar });

Or equivalently:

var cloudscraper = require('cloudscraper');
var jar = cloudscraper.jar();
cloudscraper.defaultParams.jar = jar;

Or use request's convenience function directly and optionally use request as the requester:

var request = require('request');
var cloudscraper = require('cloudscraper').defaults({ requester: request, jar: request.jar() });

Since this issue has been answered, you should close it. (You can still comment...) But this is not a general support forum. If you have a different question, open a new issue. :smile:

Good luck!

ghost commented 5 years ago

@codemanki Do you mind changing the title of this issue to How to set cookies. I'd really appreciate having commit access so I'd be able to manage a bit more on my own. None of the issues have labels and there is a tendency for people to ask the same question over an over again. We could save everybody some time by fixing these issues up when it makes sense to do so... For example which issues were bugs? So many duplicate titles.

codemanki commented 5 years ago

@pro-src done. Please accept the invite :)

codemanki commented 5 years ago

pro-src closed this 3 minutes ago