Java crawls data through selenium automation

Source: Internet
Author: User

Selenium, as a tool for testing Web applications.

1, configure the path and browser of selenium, I use Firefox

webdriver.firefox.bin=d:/tools/firefox/firefox.exewebdriver.gecko.driver=d:/project/geckodriver.exe
selenium.properties

respectively, the installation path of Firefox and the driving path of Firefox, the main driver is to drive Firefox auto-Open, click the button and other operations.

2,

 Public classselenium{Private StaticString Driver = ""; Private StaticString FireFox = ""; Static {        //read configuration file about selenium configurationProperties Properties =NewProperties (); InputStream in= Object.class. getResourceAsStream ("/selenium.properties"); Try{properties.load (in); //Drive PathDriver = Properties.getproperty ("Webdriver.gecko.driver"); //Browser PathFireFox = Properties.getproperty ("Webdriver.firefox.bin"); } Catch(Exception e) {e.printstacktrace (); } finally {            Try{in.close (); } Catch(IOException e) {e.printstacktrace (); }}} webdriver Webdriverpc=NewFirefoxdriver ();

   Public Static voidMain (string[] args) {String content= Webdriverpc.get ("http://www.baidu.com")}}

This allows you to get the HTML after the request, using the

Jsoup processing
Document doc = jsoup.parse (content);
Can get inside the content.

Java crawls data through selenium automation

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.