我已经编写了一个程序,该程序将源代码删除了两次,并使用检索到的数据中的特定信息创建了一个CSV。我的问题是,当我去保存第二部分数据时,而不是添加到创建的CSV中时,它会用新信息覆盖它。我已经提到link,但它使用了不同的类。我的代码是:添加到文件而不是覆盖
public static void scrapeWebsite() throws IOException {
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(s);
originalHtml = page.getWebResponse().getContentAsString();
obtainInformation();
originalHtml = "";
final HtmlForm form = page.getForms().get(0);
final HtmlSubmitInput button = form.getInputByValue(">");
final HtmlPage page2 = button.click();
try {
synchronized (page2) {
page2.wait(1000);
}
}
catch(InterruptedException e)
{
System.out.println("error");
}
originalHtml = originalHtml + page2.refresh().getWebResponse().getContentAsString();
obtainInformation();
}
public static void obtainInformation() throws IOException {
PrintWriter docketFile = new PrintWriter(new FileWriter("tester3.csv", true));
//创建csv文件。 (名称必须改变,重写删除文件) originalHtml = originalHtml.replace( '“', '*'); INT I = 0;
//While loop runs through all the data in the source code. There is (14) entries per page.
while(i<14) {
String plaintiffAtty = "PlaintiffAtty_"+i+"*>"; //creates the search string for the plaintiffatty
Pattern plaintiffPattern = Pattern.compile("(?<="+Pattern.quote(plaintiffAtty)+").*?(?=</span>)");//creates the pattern for the atty
Matcher plaintiffMatcher = plaintiffPattern.matcher(originalHtml); // looks for a match for the atty
while (plaintiffMatcher.find()) {
docketFile.write(plaintiffMatcher.group().toString()+", "); //writes the found atty to the file
}
i++;
}
docketFile.close(); //closes the file
}
}
相信的变化将在要进行第二方法。
的伟大工程。编辑代码以反映正确的更改。 – Ctech45