Now many web content is dynamically generated, dynamic page information extraction can use selenium. To extract dynamic page information.
One way is to start the browser to execute the JS code, then the first step is to start the browser first.
The following code:
Import Org.openqa.selenium.WebDriver;
Import Org.openqa.selenium.chrome.ChromeDriver;
public class chrometest{public
static void Main (string[] args) {
system.setproperty ("Webdriver.chrome.driver "," D:\\chromedriver\\chromedriver_win32\\chromedriver.exe ");
Create a new Webdriver object, but the new one is the chrome drive
webdriver driver =new chromedriver ();
Opens the specified Web site
driver.get ("http://www.baidu.com");
System.out.println (Driver.gettitle ());
/**
* Dr.quit () and Dr.close () can exit the browser and simply say the difference: first
Close, * If more than one page is open it is not clean, it only closes the current page. The second quit,
* is out of all webdriver all the windows, back very clean, so recommend the use of quit most of the case exit method.
* *
driver.quit ()//Exit Browser
}
}
The results of the operation are shown below:
The above results do not output "Baidu, you Know", so there are errors. I struggled with this mistake for a long time and finally solved it.
If you look closely, you can see a warning:the server did not provide any stacktrace that is reported in the above image information
In fact, the code here is not wrong, the cause of the error is that I use the Chromedriver version and the chrome version does not correspond.
The mapping relationship between the two can refer to this man's blog: http://blog.csdn.net/huilan_same/article/details/51896672
Then I downloaded a chromedriver that corresponds to my Chrome browser version and ran the code again as follows:
That's OK.