Beispiel #1
0
        public void Collect(ChromeDriver driver, MarketItemStorage storage)
        {
            List <MarketItem> newItems = new List <MarketItem>();

            for (int i = 1; i < _itemPageMaxCount; ++i)
            {
                string collectUrl = string.Format(this.MarketSellByMemberUrlFormatText, i);

                driver.Navigate().GoToUrl(collectUrl);

                var element = driver.FindElementByXPath("//*[@id='board_list']/table/tbody");

                var items = CollectItemRecord(element, storage);

                newItems.AddRange(items);

                Thread.Sleep(500);
            }

            newItems.Sort((lhs, rhs) => lhs.No.CompareTo(rhs.No));

            foreach (var marketItem in newItems)
            {
                storage.SaveItem(marketItem);

                _messageSender.SendMessage(marketItem.ToString());
            }
        }
Beispiel #2
0
        protected MarketItem[] CollectItemRecord(IWebElement element, MarketItemStorage storage)
        {
            var children = element.FindElements(By.TagName("tr"));

            var items = children.Where((child) => string.IsNullOrEmpty(child.GetAttribute("class")));

            int maxItemNo = storage.FindLastItemMarketNo();

            List <MarketItem> marketItems = new List <MarketItem>();

            foreach (var item in items)
            {
                var marketItem = CollectItemInformation(item);
                if (marketItem != null)
                {
                    if (marketItem.No > 0 && marketItem.No <= maxItemNo)
                    {
                        Console.WriteLine("{0} is max item No.", marketItem.No);
                        break;
                    }

                    marketItems.Add(marketItem);
                }
            }

            return(marketItems.ToArray());
        }