Java HTML Jsoup Document getDocument(CloseableHttpClient client, String url)

Here you can find the source of getDocument(CloseableHttpClient client, String url)

Description

get Document

License

Open Source License

Parameter

Parameter Description

Return

: Document

Declaration

public static Document getDocument(CloseableHttpClient client, String url)
        throws ClientProtocolException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;

import org.apache.http.HttpEntity;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Main {

    public static Document getDocument(CloseableHttpClient client, String url)
            throws ClientProtocolException, IOException {
        return Jsoup.parse(getString(client, url));
    }// www  . j  av  a 2s.  c o m

    public static String getString(CloseableHttpClient client, String url)
            throws ClientProtocolException, IOException {
        HttpGet getPage = new HttpGet(url);
        String htmlContent = null;
        CloseableHttpResponse response = client.execute(getPage);
        try {
            HttpEntity entity = response.getEntity();
            htmlContent = EntityUtils.toString(entity);
        } finally {
            response.close();
        }
        return htmlContent;
    }
}

Related

  1. formatDocument(Document doc)
  2. getAllText(Document document)
  3. getCategoryIds(final Document html)
  4. getContainersForLink(Document document, String link)
  5. getDivForClass(Document document, String className)
  6. getDocument(final String url)
  7. getDocument(String url)
  8. getHtmlDocument(String url)
  9. getIcon(Document doc)