Example #1
0
        public object GetValue(HtmlNode rootNode, out bool canParse)
        {
            if (!PropertyType.GetInterfaces().Contains(typeof(IEnumerable)) || !PropertyType.IsGenericType)
            {
                throw new Exception("Property have to be a generic ienumerable");
            }

            canParse = true;

            if (!string.IsNullOrEmpty(Selector))
            {
                rootNode = rootNode.QuerySelector(Selector);

                if (rootNode == null)
                {
                    if (!SkipIfNotFound)
                    {
                        throw new ElementNotFoundException(Selector);
                    }

                    canParse = false;
                }
            }

            Type itemType = PropertyType.GetGenericArguments()[0];

            return(CastIenumerableToGeneric(WebContentParser.ParseList(itemType, rootNode.InnerHtml), itemType));
        }
Example #2
0
        /// <summary>
        /// Gets list of band's albums simple list async
        /// </summary>
        public async Task <IEnumerable <AlbumBandResult> > GetAlbumsAsync(AlbumListType type)
        {
            WebDownloader wd      = new WebDownloader($@"https://www.metal-archives.com/band/discography/id/{Id}/tab/" + type.ToString().ToLower());
            string        content = await wd.DownloadDataAsync();

            return(WebContentParser.ParseList <AlbumBandResult>(content));
        }
Example #3
0
        public IEnumerable <Item> CollectItems(string url)
        {
            var websiteRequest = Task.Run(() => GetWebsiteContent(url));
            var content        = websiteRequest.Result;
            var items          = WebContentParser.ParseList <Item>(content);

            return(items);
        }
Example #4
0
        public void WebsiteParserListGeneric()
        {
            string html = WebsiteParser.Tests.Properties.Resources.SongContent;

            var result = WebContentParser.ParseList <SongModel>(html);

            Assert.AreEqual(8, result.Count());
        }
Example #5
0
        private IEnumerable <SongResult> GetSongs(string resource)
        {
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(resource);

            string songsHolder = document.QuerySelector(".table_lyrics").InnerHtml;

            return(WebContentParser.ParseList <SongResult>(songsHolder));
        }
Example #6
0
 private IEnumerable <AlbumBandResult> GetThreeRows(string resource)
 {
     return(WebContentParser.ParseList <AlbumBandResult>(resource).Take(3));
 }