21 March 2019:
Sorry, not working for now. CloudFlare changed it's protection method. Gonna work on a fix soon.
19 April 2019:
The challenge changed again... Also I didn't update the repo yet. I don't have much time to update it.
This is a libray written in Java that helps you solve the IUAM challenge in websites protected by Cloudflare.
public static void main(String... args) throws URISyntaxException, IOException, ScraperException, InterruptedException, ScriptException {
// Create CloudflareScraper object
CloudflareScraper cloudflareScraper = new CloudflareScraperBuilder(new URI("URL"))
.setConnectionTimeout(5000)
.setReadTimeout(5000)
.setChallengeDelay(4000) // At least 4000 milliseconds, otherwise Cloudflare won't give you a clearance cookie
.build();
// Check if site is protected by Cloudflare
if (cloudflareScraper.connect()) {
// Pass this cookies in your request
List<HttpCookie> cookies = cloudflareScraper.getCookies();
}
}
Add cookies using HttpURLConnection
HttpURLConnection connection = (HttpURLConnection) new URL("URL").openConnection();
for (HttpCookie cookie : cookies) {
connection.setRequestProperty("Cookie", cookie.toString());
}
Add cookies using OkHttpClient
OkHttpClient okHttpClient = new OkHttpClient();
Request.Builder requestBuilder = new Request.Builder().url("URL");
for (HttpCookie cookie : cookies) {
requestBuilder.addHeader("Cookie", cookie.toString());
}
Request request = requestBuilder.build();
Maven
<dependency>
<groupId>xyz.hexile</groupId>
<artifactId>cloudflarescraper</artifactId>
<version>1.0</version>
</dependency>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
Gradle
dependencies {
compile 'xyz.hexile:cloudflarescraper:1.0'
}
repositories {
jcenter()
}