【发布时间】:2018-01-07 21:18:52
【问题描述】:
所以我正在尝试制作一个刮板作为我的第一个项目。我相当新,我并不真正理解我编写的代码。虽然看不懂,但eclipse中似乎没有任何错误。
我写的代码是假设读取html源文件并将其逐行添加到数组列表中,直到它不能然后返回列表。我真的不知道它是否简单,但我不知道为什么它不起作用。
import java.util.ArrayList;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.List;
import java.io.BufferedReader;
public class Scraper {
public static void main(String [] args)throws Exception{
get_url_source("https://statsroyale.com/clan/99VUU8Y");
}
public static List<String> get_url_source(String URL)throws Exception {
List <String> source = new ArrayList <>();
URL stats = new URL("https://statsroyale.com/clan/99VUU8Y");
BufferedReader in = new BufferedReader(new InputStreamReader(stats.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
source.add(inputLine);
return source;
}
}
如果格式错误,我真的很抱歉。仍在尝试了解格式化的工作原理以及去哪里。 (这并不像看起来那么简单)
错误信息很长,但这里是......
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: https://statsroyale.com/clan/99VUU8Y
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at Scraper.get_url_source(Scraper.java:21)
at Scraper.main(Scraper.java:13)
【问题讨论】:
-
什么是 403 错误 - 请参阅 lifewire.com/403-forbidden-error-explained-2617989
标签: java url arraylist bufferedreader