Giter VIP home page Giter VIP logo

bramar2 / undetectedselenium Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 3.0 175 KB

Java implementation of python library undetected-chromedriver and selenium-stealth

License: GNU General Public License v3.0

Java 61.45% JavaScript 38.55%
anti-detection automation bot-detection browser chrome chromedriver chromium cloudflare cloudflare-bypass java scraping selenium selenium-stealth stealth undetected-chromedriver web-scraping undetected-driver

undetectedselenium's Introduction

Undetected Selenium

A Java implementation of undetected selenium from python library undetected-chromedriver and selenium-stealth.

Disclaimer

UndetectedChromeDriver uses the Java Reflection API to access and modify private fields specifically on the following fields:

  • org.openqa.selenium.chromium.ChromiumOptions args [Map<String, Object>]
  • org.openqa.selenium.chromium.ChromiumOptions experimentalOptions [Map<String, Object>]
  • org.openqa.selenium.MutableCapabilities caps [List<String>]

You can use SeleniumStealthOptions safely without reflection.

Install

To use the library, you can clone the repository and just copy all the src code into your project.
If you plan on using selenium-stealth, make sure to include the JS files located at src/main/resources/selenium-stealth/*.js.
The library tries to find selenium-stealth JS in classpath:selenium-stealth/*.js. SeleniumStealth will fail (or work unexpectedly) if not included.

Dependencies

Make sure these dependencies are installed and up to date:

  1. Selenium (org.seleniumhq.selenium:selenium-java)
  2. Gson (com.google.code.gson:gson)
  3. Slf4j-simple (org.slf4j:slf4j-simple)
    Slf4j-simple is used to log ChromeDriver downloads and errors for ChromeDriver downloads. If you do not want to use Slf4j-simple, you can remove the usage of it in me.bramar.undetectedselenium.DriverPatcher.
  4. Lombok (org.projectlombok:lombok)

Drivers

ChromeDrivers downloaded through undetected-selenium will be stored at the following locations.
Currently you cannot change this. But you may use your own chromedriver using UndetectedChromeDriver.driverExecutable(new File("path/to/chromedriver"))
Windows: Appdata/Roaming/java_undetected_chromedriver
Mac: Library/Application Support/java_undetected_chromedriver
Linux: .local/share/java_undetected_chromedriver
These are copied from undetected-chromedriver. Drivers are downloaded from:
CFT: https://storage.googleapis.com/chrome-for-testing-public
Legacy: https://chromedriver.storage.googleapis.com

Usage

import me.bramar.undetectedselenium.SeleniumStealthOptions;
import me.bramar.undetectedselenium.UndetectedChromeDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class Main {
    public static void main(String[] args) {
        // mimics undetected-chromedriver
        UndetectedChromeDriver uc = UndetectedChromeDriver.builder().build();
        // mimics selenium-stealth (that uses puppeteer stealth)
        ChromeDriver chromeDriver = new ChromeDriver();
        EdgeDriver edgeDriver = new ChromeDriver();
        SeleniumStealthOptions.getDefault().apply(driver);
        SeleniumStealthOptions.getDefault().apply(edgeDriver);
        // mimics both undetected-chromedriver and selenium-stealth
        // warning: may cause issues
        UndetectedChromeDriver uc2 = UndetectedChromeDriver.builder()
                .seleniumStealth(SeleniumStealthOptions.getDefault())
                .build();

        // selenium-stealth custom options
        SeleniumStealthOptions.builder()
                .languageArgument("de")
                .userAgent("CustomUserAgent")
                .renderer("Custom Renderer")
                .webglVendor("Custom WebGL Vendor")
                .platform("Custom Platform")
                .build()
                .apply(chromeDriver);
        // undetected-chromedriver custom options
        UndetectedChromeDriver uc3 = UndetectedChromeDriver.builder()
                .versionMain(125)
                .driverExecutable(driverExecutableFile) // chromedriver.exe
                .binaryExecutable(binaryExecutableFile) // chrome.exe
                .userDataDir("path/to/user/data/dir") // defaults to using temp folder
                .headless(true)
                .patchProvidedDriver(true) // defaults to false if you use custom driver, else it defaults to true
                .build();
        ChromeDriver underlyingDriverUsed = uc3.getDriver();
        
        // CF bypass that works sometimes but also slow (10s)
        // Use with caution.
        boolean success = uc3.cloudflareGet("https://nowsecure.nl");
        uc3.quit();
    }
}

Refer to me.bramar.undetectedselenium.Test for examples

Credit

undetectedselenium's People

Contributors

bramar2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

undetectedselenium's Issues

Sometimes the UndetectedChromeDriver.builder() is very slow

UndetectedChromeDriver driver = UndetectedChromeDriver.builder()
.pageLoadStrategy(PageLoadStrategy.NONE)
.headless(headless)
.driverFromCFT(true)
.versionMain(115)
.autoOpenDevtools(true)
.seleniumStealth(SeleniumStealthOptions.getDefault()).build();
Sometimes is very slow, especially when my server is low configuration, the method may be execute exceed 5 mins.

contact

hey can u send me your discord/telegram/mail? I need help

How to by pass one website, can you give me some advice?

The site url is "onewiex.com", after open url and click "Sign in", the cloudflare captcha is appear, can you give me some advice.
I have download you code, and run Test.java, that is fine, but I want you bypass my target website and I'm failure.

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.