现在的位置: 首页 > 综合 > 正文

Server returned HTTP response code: 403 for URL: http://blog.csdn.net

2017年12月17日 ⁄ 综合 ⁄ 共 348字 ⁄ 字号 评论关闭

在使用Jsoup抓取CSDN博客数据时候报http403错误,这是由于CSDN博客服务器设置了访问权限

如果是服务器端禁止抓取,那么这个你可以通过设置User-Agent来欺骗服务器

connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

利用这个原理,Jsoup代码稍作调整即可:

Connection connection =
Jsoup.connect(url);
connection.userAgent("Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
Document doc = connection.get();

抱歉!评论已关闭.