当前位置: 首页>>代码示例>>C#>>正文


C# IDocument.QuerySelectorAll方法代码示例

本文整理汇总了C#中IDocument.QuerySelectorAll方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.QuerySelectorAll方法的具体用法?C# IDocument.QuerySelectorAll怎么用?C# IDocument.QuerySelectorAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocument的用法示例。


在下文中一共展示了IDocument.QuerySelectorAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ScrapDocument

        /// <summary>
        /// Scraps the given HTML document
        /// </summary>
        /// <param name="document">HTML document to be scraped</param>
        /// <returns>The scraped Apartment</returns>
        public override ApartmentDTO ScrapDocument(IDocument document)
        {
            var apartment = new ApartmentDTO();

            // Publication Data
            apartment.PublicationUrl = document.Url;
            apartment.PublisherCode = PublisherCode.Akelius;
            var urlMatch = Regex.Match(document.Url, @"/berlin/(\d+)");
            apartment.PublisherInternalId = urlMatch.Groups[1].Value;

            // Apartment's title data (rooms & neighborhood)
            var titleElementText = document.QuerySelector("header h2").TextContent;
            var titleMatch = Regex.Match(titleElementText, "(.*) Zimmer, (.*)");
            apartment.Title = titleElementText;
            apartment.Rooms = double.Parse(titleMatch.Groups[1].Value);

            // Appartment's size
            var sizeMatch = Regex.Match(document.QuerySelector(".fact-size").TextContent, @"(\d+)m");
            apartment.Size = short.Parse(sizeMatch.Groups[1].Value);

            // Apartment's availability
            var availabilityElement = document.QuerySelector(".fact-availability");
            if (availabilityElement != null)
            {
                var availabilityMatch = Regex.Match(availabilityElement.TextContent, @"Verfügbar ab (\d+\.\d+\.\d+)");
                if (availabilityMatch.Groups.Count > 1)
                {
                    apartment.AvailableFrom = DateTime.ParseExact(availabilityMatch.Groups[1].Value, "dd.MM.yyyy", CultureInfo.InvariantCulture);
                }
            }

            // Appartment's rent
            apartment.TotalRent = double.Parse(document.QuerySelector(".fact-netrent span").TextContent);
            foreach (var feature in document.QuerySelectorAll(".features .bundle"))
            {
                var label = feature.QuerySelector(".key .factlabel");
                if (label == null)
                {
                    continue;
                }
                if (label.TextContent == "Nettokaltmiete")
                {
                    var netValueElement = feature.QuerySelector(".value").TextContent;
                    apartment.NetRent = double.Parse(netValueElement.Replace("€", string.Empty));
                }
                if (label.TextContent == "Nebenkosten")
                {
                    var netValueElement = feature.QuerySelector(".value").TextContent;
                    apartment.Charges = double.Parse(netValueElement.Replace("€", string.Empty));
                }
            }

            return apartment;
        }
开发者ID:fedebertolini,项目名称:ApartmentAggregator,代码行数:59,代码来源:AkeliusScraper.cs

示例2: TopicFormat

        private static IEnumerable<Topic> TopicFormat(IDocument document)
        {
            var topicList = document.QuerySelectorAll(".olt tr").Skip(2);

            foreach (var tp in topicList)
            {
                var topic = tp.Children[0].Children.First() as AngleSharp.Dom.Html.IHtmlAnchorElement;
                var author = tp.Children[1].Children.First() as AngleSharp.Dom.Html.IHtmlAnchorElement;
                var count = tp.Children[2].InnerHtml;
                var time = tp.Children[3];
                yield return new Topic()
                {
                    Title = topic.InnerHtml,
                    Href = topic.Href,
                    Count = count,
                    LastCommentTime = DateTime.Parse($"{DateTime.Now.ToShortDateString()} {time.InnerHtml.Split(' ').Last()}"),
                    Author = new Author() { Href = author.Href, Name = author.InnerHtml }
                };
            }
        }
开发者ID:chinaboard,项目名称:DoubanSpider,代码行数:20,代码来源:Formater.cs

示例3: getArticlePages

        public static async Task<string> getArticlePages(IDocument document, PageModel pageModel)
        {
            var content = "";

            var jqNextPage = document.QuerySelectorAll(pageModel.PagerNextSelector);
            if (jqNextPage.Any() && !string.IsNullOrEmpty(jqNextPage[0].GetAttribute("href")))
            {
                var url = pageModel.PagerNextUrlPrefix + jqNextPage[0].GetAttribute("href");
                //var parser = new HtmlParser();
                //var pageDocument = parser.Parse(getHtml(url, pageModel));
                var config = Configuration.Default.WithDefaultLoader();
                var pageDocument = await BrowsingContext.New(config).OpenAsync(url);

                content = getContent(document, pageModel);

                content += await getArticlePages(pageDocument, pageModel);
            }
            else
            {
                content = getContent(document, pageModel);
            }

            return content;
        }
开发者ID:dedabyte,项目名称:ScrapNews,代码行数:24,代码来源:Program.cs


注:本文中的IDocument.QuerySelectorAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。