java - Use data retrieved from HTTPClient into JSoup -


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

  byte [] feedbackbodie = method.getResponseBody (); System.out.println (new string);  

The above code displays the HTML code of the website. Next I want to use only some data from code which I was able to use JSoup using the following code snippet:

  document doc = jsoup.connect (url) .get ();  

In the above code I have specified the URL directly using "url". Which means that I do not need HTTP Client if I use JSoup. There is a way I can use "feedback" to integrate into JSCL code using HTTPClient so that I do not have to use the document doc = Jsoup.connect (url) .get ();

Thanks

You can HTML directly Jsoup # parse :

  document doc = jsop.parse (new string (responsebod));  

Although I have concerns about converting the byte array directly to the string, but in your case it should work fine.

On the other hand, I can use the URLConnection and get a handle on InputStream and in the string with the given charset encoding It can be parsed:

P>

  url connection connection = new URL ("http://www.stackoverflow.com"). OpenConnection (); InputStream Instream = connection.getInputStream (); String html text = org.apache.commons.io.IOUtils.toString (instream, connection.getContentEncoding ()); Document document = Jsoup.parse (html text); Elements als = document. Select ("Toddy> tr & gt; td"); (Element L: Els) {System.out.println (el.text ()); }  

will be:

  Stack Overflow server fault super-user web application Ask Ubuntu Webmasters game development tax - Latex programmers Unix & amp; Linux ask different (Apple) WordPress answer GIS Electrical Engineering Android enthusiasts Information Security database administrator Drupal North SharePoint user experience Gnitika (14) ...  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -