All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.openbox.http.page.AbstractLinkClickerParser Maven / Gradle / Ivy

There is a newer version: 2.1.6
Show newest version
package com.googlecode.openbox.http.page;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.googlecode.openbox.http.HttpClientException;

public abstract class AbstractLinkClickerParser implements LinkClickerParser {

	public abstract String parserLink(String host, Document html);

	@Override
	public LinkClicker parserNext(LinkClicker parent) {
		parent.checkIfClicked();
		try {
			String content = parent.getResponseContent();
			Document html = Jsoup.parse(content);
			String host = getHost(parent.getLink());
			String nextLink = parserLink(host, html);
			return DefaultLinkClicker.newInstance(parent, nextLink);
		} catch (Exception e) {
			throw HttpClientException.create(
					"Parser next link jump error !!!", e);
		}

	}

	private String getHost(String url) {
		return url.substring(0, url.indexOf('/', url.indexOf("//") + 2));
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy