为了账号安全,请及时绑定邮箱和手机立即绑定

删除CSV中的空白行

删除CSV中的空白行

跃然一笑 2021-04-02 14:11:37
我正在从站点抓取数据,并使用站点数据生成一个csv文件。我正在将opencsv jar和硒jar文件一起用于我的程序。CSV文件正在生成,但是在每一行之后,都会生成一个空白行。我试图消除相同但不能消除。这是我的代码:-package automation;import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.util.List;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import com.opencsv.CSVWriter;import com.opencsv.exceptions.CsvException;import com.opencsv.exceptions.CsvRequiredFieldEmptyException;import java.time.ZonedDateTime;public class RecruitmeentTestApp {    public static void main(String[] args) throws IOException, CsvException, CsvRequiredFieldEmptyException {           //WebDriver driver = new FirefoxDriver();        //Fetching Remote Control driver for Chrome browser           WebDriver driver = new ChromeDriver();           driver.get("https://www.premierleague.com/tables/");           driver.manage().window().maximize();           //Setting the file name in milliseconds of execution as per requirement           long miliSec=ZonedDateTime.now().toInstant().toEpochMilli();           File file = new File(miliSec+ ".csv") ;           WebElement table=driver.findElement(By.xpath("//table"));           List<WebElement> rowsList = table.findElements(By.tagName("tr"));           //List<WebElement> headerList=rowsList.get(0).findElements(By.xpath(".//th"));           List<WebElement> columnsList = null;           BufferedWriter writer = new BufferedWriter(new FileWriter(file));           CSVWriter csvWriter = new CSVWriter(writer,                                CSVWriter.DEFAULT_SEPARATOR,                                CSVWriter.NO_QUOTE_CHARACTER,                                CSVWriter.DEFAULT_ESCAPE_CHARACTER,                                CSVWriter.DEFAULT_LINE_END);           //As the table is static so creating headerRecord and writing it to csv file
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 426 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信