本文介绍了Java(Jsoup):如何解析http:// host:port的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Jsoup库解析网页。但由于它的地址就像主机和端口一样( http:// host:port
)(Stackoverflow不允许编写确切的东西)Jsoup抛出异常而不是解析页面。
I'm trying to parse a web page with Jsoup library. But since its adress is like host and port together (http://host:port
) (Stackoverflow does not allow to write the exact thing) Jsoup throws an exception and does not parse the page.
以下是页面地址:
这是异常日志:
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=-1, URL=http://sunucu2.radyolarburada.com:5000/
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:435)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
at Tester.getSong(Tester.java:136)
at Tester.main(Tester.java:150)
推荐答案
在中包含
request userAgent
Jsoup
Include the userAgent
in your Jsoup
request
Document document = Jsoup.connect("http://sunucu2.radyolarburada.com:5000/")
.userAgent("Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36")
.timeout(0).followRedirects(true).execute().parse();
System.out.println(document.html());
这篇关于Java(Jsoup):如何解析http:// host:port的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!