java - IOException 缺乏细节 - 403 错误

标签 java web-crawler ioexception

事情是:我有一个网络爬虫框架,以及实现这个框架的独立模块。所有这些模块都从特定新闻网站捕获新闻。

在框架中有 2 个不可预测的错误,它们是:IOException 和 SocketTimeoutException。出于明显的原因(该网站可能处于离线状态和/或正在维护中)

事情是:在一个特定的网站(THIS one)我总是得到随机的 IOExceptions。我尝试预测它,但我仍然不知道为什么会出现此错误。

我认为这是在测试阶段用请求轰炸它造成的。它不是,因为在 2 或 3 天内没有发送另一个请求它仍然会抛出错误。

简而言之:该站点不需要身份验证,它随机抛出 403。RANDOMLY

由于 403 可能是多个不同的错误,我想看看我的应用程序的具体问题是什么。

如果我能得到它是哪个 403,我可以尝试解决它。 (403.1, 403.2, ..., 403.n)

//If you guys want the code, it's a basic Jsoup get. 
//(I have also tried it with native API, 
//and still get the same random 403 errors)

//Note that I also tried it with no redirection, and still get the error
Document doc = Jsoup
    .connect("http://www.agoramt.com.br/")
    .timeout(60000)
    .followRedirects(true)
    .get();

//You may criticize about the code. But this specific line is the one 
//that throws the error. And it doesn't randomly do that to other 3k
//site connections. That's why I want to get the specifics from the 403

最佳答案

服务器可能会一时兴起返回 403。除非尊重服务器不让您进入的意愿,否则您不应该自己解决这个问题。您可以尝试阅读响应正文以了解服务器提供的详细信息,但这可能是您得到的全部。我相信,您正在寻找的 403.n 错误代码是 IIS 特定的功能,您指出的网站似乎使用 nginx,所以不要指望得到这些。

如果您的网络爬虫随机获得 403 但普通网络浏览器(来自同一 IP)从不获得 403 那么我能建议的最好的办法是让您您的网络爬虫请求 header 看起来完全就像常规网络浏览器发送的一样。对于有礼貌的网络爬虫来说,这是否是适当的行为是另一回事。

关于java - IOException 缺乏细节 - 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11052402/

相关文章:

java - 为什么 InputStream.close() 声明抛出 IOException?

java - 客户端无法连接到服务器;抛出 IOException。简单的客户端/服务器问题

java - 如何从画廊拍照并在我的应用程序中使用这张照片

c# - 在 c++/c# 中从哪里开始抓取/爬行?

automation - 计算网站中的页面数

c++ - 使用 C++ 的网络爬虫

java - 如何修复 java.io.IOException : An existing connection was forcibly closed by the remote host when downloading a file

java - 将时区存储为 ID 字符串或与 UTC 的偏移量?

java - android - 覆盖服务 move View

java - 使用 Java 发送 Outlook session 邀请