Java uses Htmlunit to crawl JS rendering pages

Source: Internet
Author: User

Demand:

Need to collect JS rendering of the page, some Web pages are JS rendering

Realize:

Based on the Htmlunit implementation:

  1. Public static void Getajaxpage () throws exception{
  2. WebClient WebClient = new WebClient ();
  3. Webclient.setjavascriptenabled (true);
  4. Webclient.setcssenabled (false);
  5. Webclient.setajaxcontroller (new Nicelyresynchronizingajaxcontroller ());
  6. Webclient.settimeout (Integer.max_value);
  7. Webclient.setthrowexceptiononscripterror (false);
  8. HtmlPage rootpage = webclient.getpage ("http://tt.mop.com/read_14304066_1_0.html");
  9. System.out.println (Rootpage.asxml ());
  10. }

Maven dependencies:

  1. <dependency>
  2. <groupId>net.sourceforge.htmlunit</groupId>
  3. <artifactid>htmlunit-core-js</artifactid>
  4. <version>2.9</version>
  5. <scope>compile</scope>
  6. </Dependency>
  7. <dependency>
  8. <groupId>net.sourceforge.htmlunit</groupId>
  9. <artifactid>htmlunit</artifactid>
  10. <version>2.9</version>
  11. <scope>compile</scope>
  12. </Dependency>

Description

Nutch plugin: nutch-htmlunit to replace the HTTP fetch component of the Nutch itself

Java uses htmlunit to crawl JS rendered pages

Related Article

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.