简体   繁体   English

java.io.IOException:服务器返回HTTP响应代码:503的URL:错误

[英]java.io.IOException: Server returned HTTP response code: 503 for URL: Error

I'm scraping data from a website by getting the HTML code from the website then parsing it in Java. 我通过从网站获取HTML代码然后从Java中解析数据来从网站上抓取数据。

I'm currently using java.net.URL as well as java.net.URLConnection. 我目前正在使用java.net.URL和java.net.URLConnection。 This is the code I use to get the HTML code from a certain website (Found on this website , slightly edited to fit my needs): 这是我用来从某个网站获取HTML代码的代码(在此网站上找到,经过略微修改以满足我的需要):

public static String getURL(String name) throws Exception{

    //Set URL
    String s = "";
    URL url = new URL(name);
    URLConnection spoof = url.openConnection();

    //Spoof the connection so we look like a web browser
    spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
    BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
    String strLine = "";

    //Loop through every line in the source
    while ((strLine = in.readLine()) != null){

        //Prints each line to the console
        s = s + strLine + "\n";
    }
    return s;
}

When I run it, the HTML code is received correctly for about 100-200 webpages. 当我运行它时,大约100-200个网页可以正确接收HTML代码。 However, before I am done grabbing HTML code, I get a "java.io.IOException: Server returned HTTP response code: 503 for URL" exception. 但是,在抓取HTML代码之前,我得到了“ java.io.IOException:服务器返回的HTTP响应代码:URL 503”异常。 I've researched this topic fully and other questions like this one do not cover the package I am using. 我已经充分研究这个话题,像其他的问题, 这样一个并不包括我现在用的包。

Thanks in advance for the help! 先谢谢您的帮助!

Maybe server have a limits. 服务器可能有限制。 In this case you can try Socket and input/outputStream instead of URLConnection 在这种情况下,您可以尝试使用Socket和input / outputStream代替URLConnection

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 奇怪的java.io.IOException:服务器返回URL的HTTP响应代码:503 - Weird java.io.IOException: Server returned HTTP response code: 503 for URL 错误打开连接 java.io.IOException:服务器返回 HTTP 响应代码:URL 501 - Error opening connection java.io.IOException: Server returned HTTP response code: 501 for URL 错误:java.io.IOException:服务器返回 HTTP 响应代码:URL 403 - Error : java.io.IOException: Server returned HTTP response code: 403 for URL URLConnection错误 - java.io.IOException:服务器返回HTTP响应代码:URL为400 - URLConnection Error - java.io.IOException: Server returned HTTP response code: 400 for URL HttpURLConnection错误-java.io.IOException:服务器返回的HTTP响应代码:URL的400 - HttpURLConnection Error - java.io.IOException: Server returned HTTP response code: 400 for URL 错误是 java.io.IOException:服务器返回 HTTP 响应代码:URL 为 500:调用 weservice 时 - Error is java.io.IOException: Server returned HTTP response code: 500 for URL: while invoking weservice java.io.IOException:服务器返回HTTP响应代码:502 - java.io.IOException: Server returned HTTP response code: 502 java.io.IOException:服务器返回HTTP响应代码:500 - java.io.IOException: Server returned HTTP response code: 500 在Java代码中获取“ java.io.IOException:服务器返回的HTTP响应代码:URL的403:” - Getting “java.io.IOException: Server returned HTTP response code: 403 for URL: ” in java code java.io.IOException:服务器针对URL:“ SoapEndPoint url”返回了HTTP响应代码:500 - java.io.IOException: Server returned HTTP response code: 500 for URL:“SoapEndPoint url”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM