GithubHelp home page GithubHelp logo

lcpo / cloudscraper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codemanki/cloudscraper

0.0 2.0 0.0 431 KB

Node.js library to bypass cloudflare's anti-ddos page

License: MIT License

JavaScript 100.00%

cloudscraper's Introduction

cloudscraper

Node.js library to bypass cloudflare's anti-ddos page.

js-semistandard-style

This library is a port of python module cloudflare-scrape with couple enhancements and test cases ;) . All grats to its author \m/

If the page you want to access is protected by CloudFlare, it will return special page, which expects client to support Javascript to solve challenge.

This small library encapsulates logic which extracts challenge, solves it, submits and returns the request page body.

You can use cloudscraper even if you are not sure if CloudFlare protection is turned on.

In general, CloudFlare has 4 types of common anti-bot pages:

  • Simple html+javascript page with challenge
  • Page which redirects to original site
  • Page with recaptcha
  • Page with error ( your ip was banned, etc)

Unfortunatelly there is no solution, if website is protected by captcha.

If you notice that for some reason cloudscraper stopped to work, do not hesitate and get in touch with me ( by creating an issue here, for example), so i can update it.

Install

npm install cloudscraper

Usage

var cloudscraper = require('cloudscraper');

cloudscraper.get('http://website.com/', function(error, response, body) {
  if (error) {
    console.log('Error occurred');
  } else {
    console.log(body, response);
  }
});

or for POST action:

cloudscraper.post('http://website.com/', {field1: 'value', field2: 2}, function(error, response, body) {
  ...
});

A generic request can be made with cloudscraper.request(options, callback). The options object should follow request's options. Not everything is supported however, for example http methods other than GET and POST. If you wanted to request an image in binary data you could use the encoding option:

cloudscraper.request({method: 'GET',
                      url:'http://website.com/image',
                      encoding: null,
                      challengesToSolve: 3, // optional, if CF returns challenge after challenge, how many to solve before failing
                      followAllRedirects: true, // mandatory for successful challenge solution
                      }, function(err, response, body) {
                      //body is now a buffer object instead of a string
});

Error object

Error object has following structure:

var error = {errorType: 0, error:...};

Where errorType can be following:

  • 0 if request to page failed due to some native reason as bad url, http connection or so. error in this case will be error event
  • 1 cloudflare returned captcha. Nothing to do here. Bad luck
  • 2 cloudflare returned page with some inner error. error will be Number within this range 1012, 1011, 1002, 1000, 1004, 1010, 1006, 1007, 1008. See more here
  • 3 this error is returned when library failed to parse and solve js challenge. error will be String with some details. ⚠️ ⚠️ Most likely it means that cloudflare have changed their js challenge.
  • 4 CF went into a loop and started to return challenge after challenge. If number of solved challenges is greater than 3 and another challenge is returned, throw an error

Running tests

Clone this repo, do npm install and then just grunt

Unknown error? Library stopped working?

Let me know, by opening issue in this repo and i will update library asap. Please, provide url and body of page where cloudscraper failed.

CloudScraper uses Request to perform requests.

WAT

Current cloudflare implementation requires browser to respect the timeout of 5 seconds and cloudscraper mimics this behaviour. So everytime you call cloudscraper.get you should expect it to return result after min 6 seconds.

TODO

  • Check for recaptcha
  • Support cookies, so challenge can be solved once per session
  • Support page with simple redirects
  • Add proper testing
  • Remove manual 302 processing, replace with followAllRedirects param
  • Parse out the timeout from chalenge page
  • Reoder the arguments in get/post/request methods and allow custom options to be passed in
  • Expose solve methods to use them independently
  • Support recaptcha solving
  • Promisification

Kudos to contributors

Dependencies

cloudscraper's People

Contributors

askmike avatar bryant1410 avatar codemanki avatar colecf avatar jngbng avatar lgaticaq avatar roflmuffin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.