npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cloudscraper-promise

v1.0.0

Published

Bypasses cloudflare's anti-ddos page

Downloads

10

Readme

cloudscraper

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

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,
                      }, 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. :warning: :warning: Most likely it means that cloudflare have changed their js challenge.

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

  • [x] Check for recaptcha
  • [ ] Support cookies, so challenge can be solved once per session
  • [x] Support page with simple redirects
  • [x] Add proper testing

Kudos to contributors

Dependencies