[Crawler learning notes] Url filtering module UrlFilter, learning notes urlfilter

Source: Internet
Author: User

[Crawler learning notes] Url filtering module UrlFilter, learning notes urlfilter


Url Filter filters the extracted URLs again. The criteria for filtering different applications are different. For example, for baidu/google search, the criteria are generally not filtered, but for vertical search or targeted crawling applications, it may only need URLs that meet certain conditions, such as URLs that do not require images, or URLs of a specific website. Url Filter is a module closely related to applications.

using System;using System.Collections.Generic;using Crawler.Common;namespace Crawler.Processing{    public class UrlFilter    {        public static List<Uri> RemoveByRegex(List<Uri> uris, params string[] regexs)        {            var uriList=new List<Uri>(uris);            for (var i = 0; i < uriList.Count; i++)            {                foreach (var r in regexs)                {                    if (!RegexHelper.IsMatch(uriList[i].ToString(), r)) continue;                    uris.RemoveAt(i);                    i--;                }            }            return uriList;        }        public static List<Uri> SelectByRegex(List<Uri> uris, params string[] regexs)        {            var uriList = new List<Uri>();            foreach (var t in uris)                foreach (var r in regexs)                    if (RegexHelper.IsMatch(t.ToString(), r))                        if(!uriList.Contains(t))                            uriList.Add(t);            return uriList;        }    }}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.