Esempio n. 1
0
        public async Task <List <BookPriceObject> > GetBookPrices(string title)
        {
            string bookIsbn;

            try
            {
                bookIsbn = Isbn.GetBookIsbn(title);
            }
            catch (ArgumentNullException ex)
            {
                throw new ApplicationException($"Could not find ISBN for title: {title}", ex);
            }
            catch (NullReferenceException ex)
            {
                throw new ApplicationException($"Could not find ISBN for title: {title}", ex);
            }

            var prices = new List <BookPriceObject>();

            foreach (var store in bookStores)
            {
                var bookData = await this.GetBookData(store, bookIsbn);

                if (bookData != null)
                {
                    prices.Add(bookData.Value);
                }
            }

            return(prices);
        }
Esempio n. 2
0
        public static string GetBookIsbn(string title)
        {
            HttpResponseMessage isbnResposne;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("User-Agent", "User-Agent-Here");
                isbnResposne = client.GetAsync(Isbn.SearchUri + title).Result;
            }

            var htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(isbnResposne.Content.ReadAsStringAsync().Result);
            var nodeWithValue = htmlDocument.DocumentNode.SelectNodes(Isbn.XPath)?.FirstOrDefault();

            return(Isbn.GetValueFromHtmlNode(nodeWithValue));
        }