0

我想从下面列出的 URL 中抓取 HTML 代码。问题是,我收到此错误:-

2016 年 8 月 14 日下午 6:40:36 booksscraper.BooksScraper 主要严重:空 org.jsoup.HttpStatusException:获取 URL 的 HTTP 错误。状态=504,URL= http://www.bkstr.com/webapp/wcs/stores/servlet/CourseMaterialsResultsView?catalogId=10001&categoryId=9604&storeId=10293&langId=-1&programId=636&termId=100043741&divisionDisplayName=%20&departmentDisplayName=ACCG&courseDisplayName=16971§ionDisplayName= 20DAVIS&demoKey=d& purpose= 在 org.jsoup.helper 的 org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:540) 上浏览 org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:590)。 bookscraper.BooksScraper 的 org.jsoup.helper.HttpConnection.get(HttpConnection.java:216) 的 HttpConnection.execute(HttpConnection.java:227)。

我已将超时设置为无穷大,但这没有帮助。该网站的 HTML 代码非常庞大,即 14833 行代码。这是问题的原因吗?

String url = "http://www.bkstr.com/webapp/wcs/stores/servlet/CourseMaterialsResultsView?catalogId=10001&categoryId=9604&storeId=10293&langId=-1&programId=636&termId=100043741&divisionDisplayName=%20&departmentDisplayName=ACCG&courseDisplayName=16971&sectionDisplayName=P15%20DAVIS&demoKey=d&purpose=browse";

Document doc = Jsoup.connect(url)
                .maxBodySize(0)
                .timeout(0)
                .get();

System.out.println(doc);
4

2 回答 2

0

这不是 Jsoup API 或您的代码问题。错误信息的原因是URL 没有响应并抛出“Gateway Timeout”错误信息(代理服务器没有收到上游服务器的及时响应)。

来自您的程序的异常消息:-

获取 URL 的 HTTP 错误。状态=504

HTTP状态码:504

504网关超时

服务器在充当网关或代理时,没有收到来自 URI(例如 HTTP、FTP、LDAP)指定的上游服务器或它在尝试完成时需要访问的其他辅助服务器(例如 DNS)的及时响应请求。

  Note: Note to implementors: some deployed proxies are known to
  return 400 or 500 when DNS lookups time out.
于 2016-08-17T10:38:19.427 回答
0

I did manage to connect to the website by setting the UserAgent as Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36. But, it took about 4 minutes to respond.

于 2016-08-17T13:18:26.517 回答