gpt4 book ai didi

Java(Jsoup) : How to parse http://host:port

转载 作者:行者123 更新时间:2023-11-30 04:17:54 25 4
gpt4 key购买 nike

我正在尝试使用 Jsoup 库解析网页。但由于它的地址就像主机和端口在一起(http://host:port)(Stackoverflow 不允许编写确切的内容)Jsoup 会抛出异常并且不会解析页面。

这是页面地址:

这是异常日志:

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)

最佳答案

在您的 Jsoup 请求中包含 userAgent

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) : How to parse http://host:port,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17890888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com