【发布时间】:2017-06-23 09:51:13
【问题描述】:
我有这个网址 http://www.zara.com/qr/1260020210042,我正在尝试获取重定向的最终网址:
String url = "http://www.zara.com/qr/1260020210042";
Response response = Jsoup.connect(url).followRedirects(true).execute();
String url2 = response.url().toString();
Response response2 = Jsoup.connect(url2).followRedirects(true).execute();
System.out.println(response2.url());
但它不打印最终重定向的 URl ,我应该改变什么? 谢谢,
编辑:
我也尝试过使用 Htmlunit,但它没有给我我需要的最终链接:
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(true);
HtmlPage page = (HtmlPage) webClient.getPage("http://www.zara.com/qr/1260020210042");
WebResponse response = page.getWebResponse();
String content = response.getContentAsString();
System.out.println(page.getUrl());
【问题讨论】:
-
在我看来,zara.com/qr/1260020210042 根本没有被重定向。它返回 200 OK。
-
是的,但如果你点击链接,它会
-
那么很可能是js相关的。用 HtmlUnit 试试,然后用 jsoup 使用重定向的 url。
-
@FredericKlein 感谢您的回答,我尝试了那里的代码,它正在向我抛出 net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: JAvascriptvalue is a type com.gargoylesoftware.htmlunit.ScriptException跨度>
标签: java cookies jsoup htmlunit