コード例 #1
0
        public AllWorkCatcher(IHelper <Proxy> proxyHelper, IHelper <Work> workHelper, IHelper <Author> authorHelper) : base(proxyHelper)
        {
            this.workHelper   = workHelper;
            this.authorHelper = authorHelper;

            isUseProxy = true;

            nextWorkPage = new AllWorkPage(string.Format("https://bcy.net/coser/allwork?&p={0}", 1));
        }
コード例 #2
0
        protected override void WebResponseHandle(string response, ICatchItem catchItem)
        {
            try
            {
                string requestDomain = string.Empty;
                requestDomain = string.Format("{0}://{1}", catchItem.Uri.Scheme, catchItem.Uri.Host);

                string html = response;
                var    doc  = new HtmlDocument();

                doc.LoadHtml(html);

                IPage page = RuleConfig.PageRule.GetRule(PageType.AllWork);

                var nodes = doc.DocumentNode.SelectNodes("//li[@class='pager__item js-nologinLink']");
                var nextPageButtonNode = nodes.ElementAt(nodes.Count - 2);

                var nextPageNode = nextPageButtonNode?.SelectSingleNode("./a");

                string href = nextPageNode?.Attributes["href"].Value;
                if (string.IsNullOrEmpty(href))
                {
                    nextWorkPage = null;
                }
                else
                {
                    nextWorkPage = new AllWorkPage(StringUtil.FillWithDomain(href, requestDomain));
                }

                var galleryNodes = page.GetNodes(doc.DocumentNode, "Gallery");
                if (galleryNodes != null)
                {
                    logger.InfoFormat("获取作品列表: 个数:{0}", galleryNodes.Count);

                    galleryNodes.ToList().ForEach(item =>
                    {
                        Work work = new Work();

                        string _address = page.GetSingleNodeValue(item, "Gallery.Address");
                        work.Address    = StringUtil.FillWithDomain(_address, requestDomain)?.AbsoluteUri;

                        //work.Originality = page.GetSingleNodeValue(item, "Gallery.Originality");

                        //work.Role = page.GetSingleNodeValue(item, "Gallery.Role");

                        work.Name = page.GetSingleNodeValue(item, "Gallery.Name");

                        Author author = new Author();

                        string authorAddress = page.GetSingleNodeValue(item, "Gallery.Author.Address");
                        author.Address       = StringUtil.FillWithDomain(authorAddress, requestDomain)?.AbsoluteUri;

                        author.Name = work.Name;

                        authorHelper.Add(author);
                        workHelper.Add(work);

                        logger.InfoFormat("获得作品: [Address:{0}], [Originality:{1}], [Role:{2}], [Name:{3}]", work.Address, work.Originality, work.Role, work.Name);
                    });
                }
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("WorkCatcher WebResponseHandle:{0}", ex);
            }
        }