public static void main(String[] args) throws IOException {
System.setProperty("src/driver/chromedriver", "G:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.premierleague.com/tables");
WebElement table;
table = driver.findElement(By.xpath("//*[@id=\"mainContent\"]/div/div[1]/div[3]/div/div"));
String dataoutput;
dataoutput = table.getText();
System.out.println(dataoutput);
String csvOutputFile = "table.csv";
File filedata = new File("src/main/table.csv");
if (filedata.exists() && !filedata.isFile()) {
FileWriter writecsv = new FileWriter("src/main/table.csv");
String datas = dataoutput;
writecsv.append(dataoutput)
}
}
这是我的代码,但它没有将数据保存到文件中。
System.out.println(dataoutput);
这一行代码会输出什么内容? - cruisepandeyPrintWriter pw = new PrintWriter(new File("test.csv")); StringBuilder sb = new StringBuilder(); sb.append(dataoutput);
。 - cruisepandey