1. The first step is to introduce dependencies
<!-- selenium -->
<dependency><groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
2. Due to the special reasons of Firefox and Google Chrome, the startup of these two browsers depends on binary files;
The link to the file is as follows:
Link: https://pan.baidu.com/s/1mhBcQBA Password: 3x3z
The code to start Google Chrome is as follows:
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe"); WebDriver driver = new ChromeDriver();
The code to start the Firefox browser is as follows:
// Specify the address of the driver (the driver of the Firefox browser) System.setProperty("webdriver.gecko.driver", "D:\\firefox\\geckodriver.exe"); // /* // * Disable images (Firefox) // */ // // close the picture // FirefoxProfile firefoxProfile = new FirefoxProfile(); // firefoxProfile.setPreference("permissions.default.image", 2); // // // turn off flash // firefoxProfile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", false); driver = new FirefoxDriver();
The following do not require drivers: WebDriver driver = new HtmlUnitDriver();
After obtaining the webpage, you can analyze the structure of the webpage, and use JSoup to parse it;