Beispiel #1
0
        /// <summary>
        /// 添加解析到的目标链接, 添加到队列中
        /// </summary>
        /// <param name="url">链接</param>
        /// <param name="priority">优先级</param>
        /// <param name="increaseDeep">目标链接的深度是否升高</param>
        public void AddTargetRequest(string url, int priority = 0, bool increaseDeep = true)
        {
            if (string.IsNullOrWhiteSpace(url) || url.Equals("#") || url.StartsWith("javascript:"))
            {
                return;
            }
            var newUrl  = Selectable.CanonicalizeUrl(url, Request.Url.ToString());
            var request = new Request(newUrl, Request.Properties);

            request.AddProperty(Priority, priority);
            AddTargetRequest(request, increaseDeep);
        }
Beispiel #2
0
        public void TestFixRelativeUrl()
        {
            string absoluteUrl = Selectable.CanonicalizeUrl("?aa", "http://www.dianping.com/sh/ss/com");

            Assert.Equal("http://www.dianping.com/sh/ss/com?aa", absoluteUrl);

            absoluteUrl = Selectable.CanonicalizeUrl("../aa", "http://www.dianping.com/sh/ss/com");
            Assert.Equal("http://www.dianping.com/sh/aa", absoluteUrl);

            absoluteUrl = Selectable.CanonicalizeUrl("..aa", "http://www.dianping.com/sh/ss/com");
            Assert.Equal("http://www.dianping.com/sh/ss/..aa", absoluteUrl);

            absoluteUrl = Selectable.CanonicalizeUrl("../../aa", "http://www.dianping.com/sh/ss/com/");
            Assert.Equal("http://www.dianping.com/sh/aa", absoluteUrl);

            absoluteUrl = Selectable.CanonicalizeUrl("../../aa", "http://www.dianping.com/sh/ss/com");
            Assert.Equal("http://www.dianping.com/aa", absoluteUrl);
        }
Beispiel #3
0
        /// <summary>
        /// 添加解析到的目标链接, 添加到队列中
        /// </summary>
        /// <param name="url">链接</param>
        /// <param name="priority">优先级</param>
        /// <param name="increaseDeep">目标链接的深度是否升高</param>
        public void AddTargetRequest(string url, int priority = 0, bool increaseDeep = true)
        {
            if (string.IsNullOrWhiteSpace(url) || url.Equals("#") || url.StartsWith("javascript:"))
            {
                return;
            }

            var newUrl     = Selectable.CanonicalizeUrl(url, Request.Url);
            var properties = new Dictionary <string, dynamic>();

            foreach (var property in Request.Properties)
            {
                properties.Add(property.Key, property.Value);
            }
            var request = new Request(newUrl, properties);

            request.AddProperty(Priority, priority);
            AddTargetRequest(request, increaseDeep);
        }