【发布时间】:2016-09-29 19:33:15
【问题描述】:
我正在尝试解析来自各个站点的导航链接。
我在使用前缀为 ./ 的相对格式的某个特定站点上遇到问题,这是代码 sn-p 与 cmets 中的相关参数值:
// url = http://megatokyo.com/strip/1456
// selector = ".next a"
// ele = <a href="./strip/1457">Next</a>
// attr = "href"
Element ele = doc.select(selector).get(index);
ele.setBaseUri(url);
String absoluteUrl = ele.absUrl(attr).trim().replaceAll("\n", "");
Jsoup 返回:
http://megatokyo.com/strip/strip/1457
实际上真正的链接是:
http://megatokyo.com/strip/1457
据我了解,Jsoup 在这里给出了正确的链接,因为 ./ 指的是当前目录 (http://megatokyo.com/strip/),这意味着锚在网站上的操作不正确。然而 Chrome、Firefox 和 IE 都将相对 URL 解析为指向下一条而不是 /strip/strip/1457。在其他情况下,有什么方法可以在不破坏相对 URL 的情况下纠正这种行为?
【问题讨论】: