Selenium用浏览器爬取数据,感觉很cool啊。趁有空赶紧写了一个hello world!
1 下载浏览器
firefox浏览器
chrome浏览器
需要本地安装过firefox或者chrome
2 动手写java
maven pom.xml中引用Selenium
org.seleniumhq.selenium
selenium-java
4.0.0-alpha-2
org.seleniumhq.selenium
selenium-server-standalone
2.53.0
写hellowolrd类
public static void loginYY( String username,String password){
System.setProperty("webdriver.chrome.driver", "F://wb//chromedriver.exe");
ChromeOptions options = new ChromeOptions();
ChromeDriver webDriver = new ChromeDriver(options);
String url = "http://www.yy.com/98187265/98187265";
webDriver.get(url); //
// 与浏览器同步非常重要,必须等待浏览器加载完毕
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//找到登陆按钮 并点击
webDriver.findEleme