[英]Dowloading list of References from Google Scholar
I have stored the references from a research paper in a list (as shown below): I want to download them all from google scholar. 我已将研究论文的参考文献存储在一个列表中(如下所示):我想从Google Scholar下载所有参考文献。 I have successfully downloaded a single paper by giving its url below, What I need to do now is that as i have stored all the references from Research paper in the list(there are 15 references in list which means atleast 5 of them would be in pdf), I want to run the list on Google Scholar and download the avaialble pdfs of references. 我已经通过在下面提供其网址成功下载了一篇论文,现在我需要做的是,因为我已将研究论文的所有参考文献都存储在列表中(列表中有15个参考文献,这意味着其中至少有5个参考文献会出现在列表中)。 pdf),我想在Google学术搜索上运行该列表并下载可用的参考pdf。 If pdf is not avaialble for a reference, it must display "Pdf is not avaialable": I have shared the code to download a single one, I dont know how to ammend the code for the list to download multiple papers. 如果pdf无法提供参考,它必须显示“ Pdf不可用”:我已经共享了下载单个代码的代码,我不知道如何修改列表中的代码以下载多篇论文。
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();
}
}
}
You just pass the query to the Url with a loop: 您只需通过循环将查询传递给网址:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.Scanner;
/**
* User: lihongxu
* Date: 17/6/13
* Time: 19:42
* Comments
*/
public class Test {
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);
}
}
}
s.close();// LIST completed
// code to download the paper from scholar
for (String query : list) {
try {
Document doc = Jsoup
.connect("https://scholar.google.com.pk/scholar?q=" + query)
.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());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.