Java-HttpClient-Douban movie rankings,

Source: Internet
Author: User

Java-HttpClient-Douban movie rankings,
Public class TestHttpClient {public static void main (String [] args) throws ClientProtocolException, IOException {// create httpClient instance CloseableHttpClient httpClient = HttpClients. createDefault (); // create httpGetHttpGet httpGet = new HttpGet ("https://movie.douban.com/cinema/nowplaying/nanjing/"); System. out. println (httpGet. getURI (); // execute the get request and receive the response information CloseableHttpResponse response = httpClient.exe cute (httpGet); // obtain the response Entity HttpEntity entity = response. getEntity (); // print the response status System. out. println (response. getStatusLine (); System. out. println ("---------------------------------"); if (entity! = Null) {String web = EntityUtils. toString (entity, "UTF-8"); // System. out. println ("response content length" + entity. getContentLength (); // System. out. println ("response content" + web); Document doc = Jsoup. parse (web); // obtain the ranking title Elements title = doc. getElementsByClass ("movie_ranking_time"); for (Element element: title) {System. out. println (element. text ();} // obtain the ranking type Elements name = doc. select ("ul. tab_nav> li "); // obtain the ranking table Elements content = doc. select ("ul. view_1 "); for (int I = 0; I <name. size (); I ++) {System. out. println (name. get (I ). text (); Elements movie = content. get (I ). select ("li"); for (int j = 0; j <movie. size (); j ++) {System. out. println (movie. get (j ). text () ;}} System. out. println ("---------------------------------"); response. close (); httpClient. close ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.