0
Iam試圖下載我通過以下代碼存儲在Google學者列表中的研究論文,我已經測試了20+次程序,大約一個小時前,我再次測試它,並且此錯誤彈出。此代碼是我的BS最後一年項目的一部分,我需要解決這個問題。我搜索了這個錯誤,並且嘗試了很多東西。我需要幫助來克服這一點。如果我改變了我的IP,這個問題會解決嗎?如何解決org.jsoup.HttpStatusException:獲取URL的HTTP錯誤。狀態= 503
Scanner s = new Scanner(new File("E:\\ref11.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();
for (String query : list)
try {
//var a= doc.replace(" ","+");
Document doc = Jsoup
.connect("https://scholar.google.com.pk/scholar?q=" +query).timeout(30000).followRedirects(true)
.maxBodySize(1024*1024*3)
.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:\\Referenced Papers\\" +title);
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();
}