com.ninja-beans.crawler:cloudflare-iuam-solver-dist

IuamSolver is the class for breaking through the Cloudflare's "I am Under Attack Mode".

License

License

Categories

Categories

Ninja User Interface Web Frameworks
GroupId

GroupId

com.ninja-beans.crawler
ArtifactId

ArtifactId

cloudflare-iuam-solver-dist
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

pom
Description

Description

com.ninja-beans.crawler:cloudflare-iuam-solver-dist
IuamSolver is the class for breaking through the Cloudflare's "I am Under Attack Mode".

Download cloudflare-iuam-solver-dist

How to add to project

<!-- https://jarcasting.com/artifacts/com.ninja-beans.crawler/cloudflare-iuam-solver-dist/ -->
<dependency>
    <groupId>com.ninja-beans.crawler</groupId>
    <artifactId>cloudflare-iuam-solver-dist</artifactId>
    <version>0.1.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.ninja-beans.crawler/cloudflare-iuam-solver-dist/
implementation 'com.ninja-beans.crawler:cloudflare-iuam-solver-dist:0.1.0'
// https://jarcasting.com/artifacts/com.ninja-beans.crawler/cloudflare-iuam-solver-dist/
implementation ("com.ninja-beans.crawler:cloudflare-iuam-solver-dist:0.1.0")
'com.ninja-beans.crawler:cloudflare-iuam-solver-dist:pom:0.1.0'
<dependency org="com.ninja-beans.crawler" name="cloudflare-iuam-solver-dist" rev="0.1.0">
  <artifact name="cloudflare-iuam-solver-dist" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.ninja-beans.crawler', module='cloudflare-iuam-solver-dist', version='0.1.0')
)
libraryDependencies += "com.ninja-beans.crawler" % "cloudflare-iuam-solver-dist" % "0.1.0"
[com.ninja-beans.crawler/cloudflare-iuam-solver-dist "0.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.ninja-beans.crawler : cloudflare-iuam-solver-cli jar 0.1.0

Project Modules

There are no modules declared in this project.

Cloudflare-IUAM-Solver

A simple "Pure Java" library and cli tool to breaking through the Cloudflare's anti-bot mechanism (a.k.a "I'm Under Attack Mode", or IUAM), implemented with HTMLUnit.

Maven Central with version prefix filter GitHub Java

Prerequisites

  • JDK 11

CLI Tool

Install

$ curl -LO https://github.com/ninja-beans/cloudflare-iuam-solver/releases/download/0.1.0/cfis
$ chmod +x cfis

Usage

Print a cookie string.

$ ./cfis -c https://www.example.com
cf_clearance=XXXXXXXXXXXXXXXXXXXX-XXXXXXXXXX-X-XXX;__cfduid=XXXXXXXXXXXXXXXXXXXX;

Download a html content with curl.

$ ./cfis -c > cookie.txt
$ ./cfis -u > ua.txt
$ curl -s --cookie "$(cat cookie.txt)" -A "$(cat ua.txt)" https://www.example.com/

Extract all images with curl and xmllint.

$ eval $(./cfis --curl https://www.example.com/) | xmllint --xpath "//img" --html - 2> /dev/null

Java Library

Install

<dependency>
  <groupId>com.ninja-beans.crawler</groupId>
  <artifactId>cloudflare-iuam-solver-parent</artifactId>
  <version>0.1.0</version>
  <type>pom</type>
</dependency>

Usage

Scraping with Java 11 HttpClient and Jsoup.

public class App {
  public static void main(final String[] args) throws IOException, InterruptedException {
    var url = args[0];
    var result = IuamSolver.solve(url);

    // 1. Create HttpClient
    var client = HttpClient
        .newBuilder()
        .version(Version.HTTP_1_1)
        .followRedirects(Redirect.NORMAL)
        .cookieHandler(result.getCookieManager()).build();

    // 2. Send the request and get the response
    var request = HttpRequest.newBuilder().header("Accept", "*/*")
        .header("User-Agent", result.getResponse().getUserAgent())
        .GET()
        .uri(URI.create(url))
        .build();
    var response = client.send(request, BodyHandlers.ofString(StandardCharsets.UTF_8));

    // 3. Parse the response
    var doc = Jsoup.parse(response.body(), url);
    var elm = doc.getElementById("title");
    System.out.println(doc.title());
    System.out.println(elm.html());
  }
}

Versions

Version
0.1.0
0.0.1