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, body, response) {
if (error) {
console.log('Error occurred');
} else {
console.log(body, response);
}
});
##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 event1
cloudflare returned captcha. Nothing to do here. Bad luck2
cloudflare returned page with some inner error.error
will beNumber
within this range1012, 1011, 1002, 1000, 1004, 1010, 1006, 1007, 1008
. See more here3
this error is returned when library failed to parse and solve js challenge.error
will beString
with some details.⚠️ ⚠️ 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
- Check for recaptcha
- Support cookies, so challenge can be solved once per session
- Support page with simple redirects
- Add proper testing
Kudos to contributors
Dependencies
- request@2.49.0 https://github.com/request/request
- tough-cookie@0.12.1 https://github.com/goinstant/tough-cookie