package test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test7 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe"); // 请设置 chromedriver 的实际路径
WebDriver driver = new ChromeDriver();
String url = "https://www.igengmei.com/";
driver.get(url);
Thread.sleep(3000); // 等待页面加载完成,可适当调整等待时间
WebElement elem = driver.findElement(By.tagName("body"));
String html = elem.getAttribute("innerHTML");
System.out.println(html);
//driver.quit();
}
}
https://chromedriver.chromium.org/downloads 这里下载chromedirver.exe和浏览器版本号对应,放在浏览器同一个目录里面。