コード例 #1
0
        protected override void Handle(Page page)
        {
            // 利用 Selectable 查询并构造自己想要的数据对象
            var    totalVideoElement = page.Selectable.Select(Selectors.XPath("//*[@id='total_videonum']"));
            var    id       = totalVideoElement.XPath("@id").GetValue();
            string videoNum = totalVideoElement.GetValue();

            //得到电影类别
            var linqNodes    = page.Selectable.Select(Selectors.XPath("//*[@id='filterPanel']/div[2]/ul")).XPath("li").Nodes();
            var videoCountry = new List <string>();

            foreach (var node in linqNodes)
            {
                string text = node.GetValue(ValueOption.InnerText);
                videoCountry.Add(text);
                //Console.WriteLine($"{text}");
            }

            //整合实体
            var results = new YouKu()
            {
                id           = id,
                videoNum     = Convert.ToInt32(videoNum),
                videoCountry = videoCountry
            };

            // 以自定义KEY存入page对象中供Pipeline调用
            page.AddResultItem("VideoResult", results);
        }
コード例 #2
0
ファイル: YoukuPipeline.cs プロジェクト: happlyfox/FoxCrawler
        public override void Process(IEnumerable <ResultItems> resultItems, ISpider spider)
        {
            ResultItems   result  = resultItems.First();
            StringBuilder builder = new StringBuilder();

            YouKu entry = result.Results["VideoResult"];

            builder.Append($"输出 [YouKu {entry.id}] {entry.videoNum}");
            Console.WriteLine(builder.ToString());

            // Other actions like save data to DB. 可以自由实现插入数据库或保存到文件
        }