コード例 #1
0
        public Selenium(Config config, AsinGroup asinGroup)
        {
            var options = new ChromeOptions {
                PageLoadStrategy = PageLoadStrategy.Default,
            };

            webDriver = new ChromeDriver(options);
            webDriver.Manage().Cookies.DeleteAllCookies();
            webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

            this.config    = config;
            this.asinGroup = asinGroup;
        }
コード例 #2
0
        bool CheckPrice(IWebElement element, AsinGroup asinGroup)
        {
            var priceText = priceRegex.Match(element.Text.Replace(",", "")).Groups["dollars"].Value;
            var price     = Convert.ToInt32(priceText);

            if (price <= asinGroup.MaxPrice && price >= asinGroup.MinPrice)
            {
                Green($"Price ${price}. Purchasing item!!!");

                webDriver.FindElement(By.Id("buy-now-button")).Click();
                return(true);
            }

            Red($"Price invalid: ${price}");
            return(false);
        }
コード例 #3
0
        public bool CheckForItems(string asin, AsinGroup asinGroup)
        {
            Console.WriteLine($"Checking price of {asin}");

            webDriver.Url = $"https://{config.Domain}/dp/{asin}";

            // Find first element: out of stock, price, other offers only
            var element = webDriver.FindElements(
                By.XPath("//div[@id='outOfStock'] | //span[@id='price_inside_buybox'] | //span[@data-action='show-all-offers-display']")
                ).FirstOrDefault();

            if (element == null)
            {
                Console.WriteLine("UNEXPECTED STATE.");
                return(false);
            }

            var id = element.GetAttribute("id");

            if (id == "outOfStock")
            {
                Red("Out of stock.");
                return(false);
            }

            if (id == "price_inside_buybox")
            {
                return(CheckPrice(element, asinGroup));
            }

            if (element.GetAttribute("data-action") == "show-all-offers-display")
            {
                Red("Only other offers.");
                return(false);
            }

            return(false);
        }