我有这个网址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());