基于selenium的简单Java爬虫

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Login {
private static void login() {
WebDriver driver = null;
System.setProperty(“webdriver.chrome.driver”, “D:/development/chromedriver.exe”);
driver = new ChromeDriver();
driver.get(“http://www.weather.com.cn/“);
driver.findElement(By.id(“btnZip”)).click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println(“当前URL 1 :” + driver.getCurrentUrl());
System.out.println(web.getText());
if(driver != null){
driver.close();
public static void main(String[] args) throws Exception{
login();
}
}

  1. 爬取天气网的天气情况

你可能感兴趣的:(java)