A java library to bypass Cloudflare's anti-bot and get the page contents for webscraping app. This is the java implementation of the CfScrape api.
Add repository :
repositories {
maven {
url 'https://jitpack.io'
}
}
Add dependency :
dependencies {
compile 'com.github.iambluedev1:cfscrape-java:1.0.0'
}
Add repository :
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Add dependency :
<dependency>
<groupId>com.github.iambluedev1</groupId>
<artifactId>cfscrape-java</artifactId>
<version>1.0.0</version>
</dependency>
Firstly you need to get the CfScrape object :
CfScrape cfScrape = CfScrape.get();
cfScrape.setUrl("an url");
By default, the url is http://127.0.0.1:8888
cfScrape.setApiHost("an url");
There are two ways to scrape a website : asynchrone and synchrone ways.
cfScrape.getAsyncHtml(new Callback<String>() {
public void call(String html) {
System.out.println(html);
}
});
cfScrape.getAsyncResponse(new Callback<ApiResponse>() {
@Override
public void call(ApiResponse v) {
String html = v.getHtml();
String token = v.getToken();
String url = v.getUrl();
}
});
String html = cfScrape.getSyncHtml();
ApiDirectResponse response = cfScrape.getSyncResponse();
String html = response.getHtml();
String url = response.getUrl();
These examples can be viewed in the examples package