public void FixRelativeUrl() { var absoluteUrl = UriUtils.CanonicalizeUrl("?aa", "http://www.dianping.com/sh/ss/com"); Assert.Equal("http://www.dianping.com/sh/ss/com?aa", absoluteUrl); absoluteUrl = UriUtils.CanonicalizeUrl("../aa", "http://www.dianping.com/sh/ss/com"); Assert.Equal("http://www.dianping.com/sh/aa", absoluteUrl); absoluteUrl = UriUtils.CanonicalizeUrl("..aa", "http://www.dianping.com/sh/ss/com"); Assert.Equal("http://www.dianping.com/sh/ss/..aa", absoluteUrl); absoluteUrl = UriUtils.CanonicalizeUrl("../../aa", "http://www.dianping.com/sh/ss/com/"); Assert.Equal("http://www.dianping.com/sh/aa", absoluteUrl); absoluteUrl = UriUtils.CanonicalizeUrl("../../aa", "http://www.dianping.com/sh/ss/com"); Assert.Equal("http://www.dianping.com/aa", absoluteUrl); // 只有相对路径需要做补充 var selectable1 = new HtmlSelectable("<div><a href=\"/a/b\">aaaaaaab</a></div>", "http://www.b.com"); var value1 = selectable1.Links().First(); Assert.Equal("http://www.b.com/a/b", value1); // 绝对路径不需要做补充 var selectable2 = new HtmlSelectable("<div><a href=\"http://www.aaaa.com\">aaaaaaab</a></div>", "http://www.b.com", false); var value2 = selectable2.SelectList(Selectors.XPath(".//a")).First().Value; Assert.Equal("aaaaaaab", value2); }