Exemplo n.º 1
0
        public async Task ParseWebResponse(FeedSource source, WebResponse response)
        {
            await Console.Error.WriteLineAsync("[Builder/Html] Parsing Html");

            // Parse the HTML
            HtmlDocument html = new HtmlDocument();

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                html.LoadHtml(await reader.ReadToEndAsync());

            HtmlNode document = html.DocumentNode;

            document.AbsolutifyUris(new Uri(source.Feed.Url));


            await Console.Error.WriteLineAsync("[Builder/Html] Generating feed content");

            // Add the title
            await feed.WriteTitle(ReferenceSubstitutor.Replace(source.Feed.Title, document));

            await feed.WriteSubtitle(ReferenceSubstitutor.Replace(source.Feed.Subtitle, document));

            // Add the logo
            if (source.Feed.Logo != null)
            {
                HtmlNode logoNode = document.QuerySelector(source.Feed.Logo.Selector);
                xml.WriteElementString("logo", logoNode.Attributes[source.Feed.Logo.Attribute].Value);
            }

            // Add the feed entries
            foreach (HtmlNode nextNode in document.QuerySelectorAll(source.Entries.Selector))
            {
                await addEntry(source, nextNode);
            }
        }