cloudflare-bypasser

Crates.iocloudflare-bypasser
lib.rscloudflare-bypasser
version0.2.0
sourcesrc
created_at2019-02-10 20:35:13.804518
updated_at2020-03-04 16:49:42.493579
descriptionA crate to bypass Cloudflare's anti-bot page, inspired by python module [cloudflare-scrape](https://github.com/Anorov/cloudflare-scrape)
homepage
repositoryhttps://github.com/AurevoirXavier/cloudflare-bypasser
max_upload_size
id113953
size11,654
Xavier Lau (AurevoirXavier)

documentation

README

Intro

cloudflare-bypasser

Inspired by python module cloudflare-scrape

Require

  • Node.js

Example

extern crate cloudflare_bypasser;
extern crate reqwest;

fn main() {
    const WEBSITE: &'static str = "https://example.com";

    // quick start
    let mut bypasser = {
        cloudflare_bypasser::Bypasser::default()
    };

    // customize
    let mut bypasser = {
        cloudflare_bypasser::Bypasser::default()
            .retry(30)                      // retry times, it might be 10000, depends on your network environment, default 0 (infinity)
            .proxy("http://127.0.0.1:1087") // use proxy, default None
            .random_user_agent(true)        // use random user agent, default false
            .user_agent("Mozilla/5.0")      // specify user agent manually, default ""
            .wait(5);                       // cloudflare's waiting time, but in my test it can be 0, default 0
    };                           

    // to pass the verify both of the cookie and user agent are needed
    let (cookie, user_agent);
        loop {
            if let Ok((c, ua)) =  bypasser.bypass(WEBSITE) {
                cookie = c;
                user_agent = ua;
                break;
            }
        }
    
    // use reqwest without proxy
    {
        // 1
        {
            let client = {
                let headers = {
                    let mut h = reqwest::header::HeaderMap::new();
                    h.insert(reqwest::header::COOKIE, cookie);
                    h.insert(reqwest::header::USER_AGENT, user_agent);
                    h
                };
                
                reqwest::ClientBuilder::new()
                    .default_headers(headers)
                    .build()
                    .unwrap()
            };
                
            let text = client.get(WEBSITE)
                .send()
                .unwrap()
                .text()
                .unwrap();
            println!("{}", text);
        }
        
        // 2
        {
            let text = reqwest::Client::new()
                .get(WEBSITE)
                .header(reqwest::header::COOKIE, cookie)
                .header(reqwest::header::USER_AGENT, user_agent)
                .send()
                .unwrap()
                .text()
                .unwrap();
            println!("{}", text);
        }
    }
    
    // use reqwest with proxy
    {
        let client = {
            let headers = {
                let mut h = reqwest::header::HeaderMap::new();
                h.insert(reqwest::header::COOKIE, cookie);
                h.insert(reqwest::header::USER_AGENT, user_agent);
                h
            };
            
            reqwest::ClientBuilder::new()
                .default_headers(headers)
                .proxy(reqwest::Proxy::all("http://127.0.0.1:1087").unwrap())
                .build()
                .unwrap()
        };
            
        let text = client.get(WEBSITE)
            .send()
            .unwrap()
            .text()
            .unwrap();
        println!("{}", text);
    }
}
Commit count: 35

cargo fmt