在 java 中,我想从 URL(instagram)读取并保存所有 HTML,但得到错误 429(请求太多)。我认为这是因为我试图阅读比请求限制更多的行。
StringBuilder contentBuilder = new StringBuilder();
try {
URL url = new URL("https://www.instagram.com/username");
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String str;
while ((str = in.readLine()) != null) {
contentBuilder.append(str);
}
in.close();
} catch (IOException e) {
log.warn("Could not connect", e);
}
String html = contentBuilder.toString();
错误就是这样;
Could not connect
java.io.IOException: Server returned HTTP response code: 429 for URL: https://www.instagram.com/username/
它还表明由于这条线而发生错误
InputStream is =con.getInputStream();
有谁知道我为什么会收到此错误和/或如何解决它?