示例#1
0
        protected override void Handle(Page page)
        {
            Cnblog cnblog = new Cnblog();

            cnblog.Title   = page.Selectable.Select(Selectors.XPath("//a[@id='cb_post_title_url']")).GetValue();
            cnblog.Content = page.Selectable.Select(Selectors.XPath("//*[@id='cnblogs_post_body']")).GetValue();
            cnblog.Url     = page.Url;
            page.AddResultItem("detail", cnblog);
        }
示例#2
0
 public void Process(IEnumerable <ResultItems> resultItems, ISpider spider)
 {
     foreach (var resultItem in resultItems)
     {
         Cnblog     cnblog = resultItem.Results["detail"];
         FileStream fs     = File.Create(path + "\\" + cnblog.Title.Substring(0, 3) + ".txt");
         byte[]     bytes  = UTF8Encoding.UTF8.GetBytes("Url:" + cnblog.Url + Environment.NewLine + cnblog.Content);
         fs.Write(bytes, 0, bytes.Length);
         fs.Flush();
         fs.Close();
     }
 }
        protected override void Handle(Page page)
        {
            var           totalCnblogElements = page.Selectable.SelectList(Selectors.XPath("//div[@class='post_item']")).Nodes();
            List <Cnblog> results             = new List <Cnblog>();

            foreach (var cnblogElement in totalCnblogElements)
            {
                var cnblog = new Cnblog();
                cnblog.Title  = cnblogElement.Select(Selectors.XPath(".//div[@class='post_item_body']/h3/a")).GetValue();
                cnblog.Url    = cnblogElement.Select(Selectors.XPath(".//div[@class='post_item_body']/h3")).Links().GetValue();
                cnblog.Author = cnblogElement.Select(Selectors.XPath(".//div[@class='post_item_foot']/a[1]")).GetValue();
                results.Add(cnblog);
            }
            page.AddResultItem("Result", results);
        }