Giter VIP home page Giter VIP logo

geekhub-java-api's Introduction

geekhub-java-api

geekhub.com Java API 爬虫版

Depends

(Java >8, Lombok, HttpClient, Slf4j)

Usage

Create Instance

Login With username and password

GeekHubApi gh = GeekHubApi.builder()
		.httpHelper(HttpClientHelper.create(GeekHubApi.DEFAULT_URL_BASE, GeekHubApi.USER_AGENT))
		.identityProvider(GeekHubCommonAuth.builder().dataPath("<data-path>").username("<username>")
				.password("<password>").build())
		.build();
gh.init();

For first run, there will be a captcha image file in <data-path>/tmp, such as 9e916356-0e73-46cc-8d01-85827d35c1cd.jpg. Create a text file with the captcha value, and rename it to 9e916356-0e73-46cc-8d01-85827d35c1cd.jpg.txt.

And If the session is expired, it will run again when processing some pages which need login.

Login with cookies

For custom cookies:

GeekHubApi gh = GeekHubApi.builder()
		.httpHelper(HttpClientHelper.create(GeekHubApi.DEFAULT_URL_BASE, GeekHubApi.USER_AGENT))
		.identityProvider(new GeekHubIdentityProvider() {
			@Override
			public List<Cookie> loadCookie(GeekHubApi geekHubApi) {
				// load your cookie from anywhere
				return null;
			}
		}).build();
gh.init();

Checkins (needs login)

boolean checkedIn = gh.checkIns();

Fetch Posts

GeekHubApiResult<GeekHubPost> apiResult = gh.fetchPost(PageDefination.DEFAULT_POST, "2296");
String poster = apiResult.getContent().getPoster();	// It will be '37丫37'
GeekHubApiResult<MoleculePost> apiResult = gh.fetchPost(PageDefination.MOLECULE, "1");
String title = apiResult.getContent().getTitle();// It will be '{ 活动队列,暂未开始 } GeekHub Launch!抢到楼层,这一箱 AirPods 2 就是你的了。'

Fetch Users

GeekHubApiResult<GeekHubUserProfile> apiResult = gh.fetchUserProfile("GM");

Listener

gh.addCableListener(update -> {
	for(GeekHubPostItem item : update.getPosts()){
		// do something
	}
	for(GeekHubComment comment : update.getComments()){
		// do something
	}
});

geekhub-java-api's People

Contributors

dallaslu avatar

Watchers

 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.