我已将研究论文的参考文献存储在一个列表中(如下所示):我想从谷歌学者那里下载它们。我已经通过在下面给出它的 url 成功下载了一篇论文,我现在需要做的是,因为我已经将研究论文中的所有参考文献都存储在列表中(列表中有 15 个参考文献,这意味着其中至少有 5 个在pdf),我想在 Google Scholar 上运行该列表并下载可用的 pdf 参考文献。如果pdf不能参考,一定要显示“Pdf is not avaialable”:我已经分享了下载单篇的代码,不知道怎么修改代码列表下载多篇论文。
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(new File("D:\\ref.txt"));
ArrayList<String> list = new ArrayList<String>();
while (s.hasNextLine()){
list.add(s.nextLine());
{
for (String Z : list)
{
System.out.println(Z);
}
}
}
//System.out.println("LISTZ:" +list);
s.close();//LIST completed
//code to download the paper from scholar
try {
//var a= doc.replace(" ","+");
Document doc = Jsoup
.connect("https://scholar.google.com.pk/scholar?q=%5B3%5D+W.+H.+Walters%2C+%E2%80%9CGoogle+scholar+coverage+of+a+multidisciplinary+field%2C%E2%80%9D+Information+Processing+%26+Management+%2C+vol.+43%2C+no.+4%2C+pp.+1121+%E2%80%93+1132%2C+July+2007.&btnG=&hl=en&as_sdt=0%2C5")
.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36")
.get();
String title = doc.title();
System.out.println("title : " + title);
Elements links = doc.select("div.gs_ggsd").select("a[href]");
//Element = doc.select("div.gs_ggs gs_fl").first();
for (Element link : links) {
//System.out.println("\nlink : " + link.attr("href"));
URL website = new URL(link.attr("href"));
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("D:\\paper.pdf");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
// System.out.println("text : " + link.text());
}
/* ByteArrayOutputStream href = new ByteArrayOutputStream();
PrintStream PS = new PrintStream(href);
PrintStream old = System.out;
System.setOut(PS);
System.out.println("Here: " + href.toString());*/
catch (IOException e) {
e.printStackTrace();
}
}
}