Use data retrieved from HTTPClient in JSoup

I am using HTTPClient to connect to a website. The following code snippet is used for this purpose:

 byte[] responseBody = method.getResponseBody();
 System.out.println(new String(responseBody));

The above code displays the html code of the website. Next, I wanted to access only some data from the code, which I could access using JSoup using the following code fragment:

Document doc = Jsoup.connect(url).get();

In the above code, I explicitly specified the website URL using "url". that I do not require HTTPClient if I use JSoup. Is there a way that I can use the "responseBody" obtained with the HTTPClient that needs to be integrated into the JSoup code, so I don't need to use Document doc = Jsoup.connect (url) .get ();

thank

+3
source share
2

HTML Jsoup#parse:

Document doc =  Jsoup.parse(new String(responseBody));

String , .

URLConnection InputStream String :

URLConnection connection = new URL("http://www.stackoverflow.com").openConnection();
        InputStream inStream = connection.getInputStream();
        String htmlText = org.apache.commons.io.IOUtils.toString(inStream, connection.getContentEncoding());

        Document document = Jsoup.parse(htmlText);
        Elements els = document.select("tbody > tr > td");

        for (Element el : els) {
            System.out.println(el.text());
        }

:

Qaru Server Fault Super User Web Applications Ask Ubuntu Webmasters Game Development TeX - LaTeX
Programmers Unix & Linux Ask Different (Apple) WordPress Answers Geographic Information Systems Electrical Engineering Android Enthusiasts Information Security
Database Administrators Drupal Answers SharePoint User Experience Mathematica more (14)
...
+3

All Articles