GithubHelp home page GithubHelp logo

00mjk / cloudflare-bypasser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hack-ink/cloudflare-bypasser

0.0 0.0 0.0 46 KB

A Rust crate to bypass Cloudflare's anti-bot page.

Home Page: https://crates.io/crates/cloudflare-bypasser

License: MIT License

Rust 100.00%

cloudflare-bypasser's Introduction

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::blocking::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);
    }
}

cloudflare-bypasser's People

Contributors

aurevoirxavier avatar mglolenstine avatar rnbguy 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.