Jsoup重定向到URL

Jsoup重定向到URL,第1张

Jsoup重定向到URL

Response对象具有url()方法,该方法应该为您提供最终的url。所以你可以喜欢

String url = "http://t.co/i5dE1K4vSs";Response response = Jsoup.connect(url).followRedirects(true).execute();System.out.println(response.url())

如果要获取中间重定向,则应关闭跟随重定向,然后检查标题“位置”。例如

String url = "http://t.co/i5dE1K4vSs";Response response = Jsoup.connect(url).followRedirects(false).execute();System.out.println(response.header("location"));

如果它具有多个重定向,则需要递归调用URL。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5615823.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存