예제 #1
0
            protected override Task ParseAsync(DataFlowContext context)
            {
                var newsList = context.Selectable.SelectList(Selectors.XPath(".//div[@class='news_block']"));

                foreach (var news in newsList)
                {
                    var title   = news.Select(Selectors.XPath(".//h2[@class='news_entry']"))?.Value;
                    var url     = news.Select(Selectors.XPath(".//h2[@class='news_entry']/a/@href"))?.Value;
                    var summary = news.Select(Selectors.XPath(".//div[@class='entry_summary']"))?.Value;
                    var views   = news.Select(Selectors.XPath(".//span[@class='view']"))?.Value.Replace(" 人浏览", "");

                    if (!string.IsNullOrWhiteSpace(url))
                    {
                        var request = context.CreateNewRequest(new Uri(url));
                        request.Properties.Add("title", title);
                        request.Properties.Add("url", url);
                        request.Properties.Add("summary", summary);
                        request.Properties.Add("views", views);

                        context.AddFollowRequests(request);
                    }
                }

                return(Task.CompletedTask);
            }