示例#1
0
 public Price Search(string url)
 {
     //var url = Helper.CheckUrl(link);
     if (string.IsNullOrWhiteSpace(url))
     {
         return(null);
     }
     if (url.Contains("product.suning.com"))
     {
         driver.Navigate().GoToUrl(url);
         var price = SUNINGPriceParser.ExtractPrice(driver);
         Console.WriteLine(JsonConvert.SerializeObject(price));
         return(price);
     }
     else if (url.StartsWith("https://item.jd.com/"))
     {
         //driver.Navigate().GoToUrl(url);
         //var text = driver.FindElement(By.ClassName("summary-price-wrap")).Text;
         //var title = driver.FindElement(By.ClassName("sku-name")).Text;
         //var price = ParsePrice(text, url, outputPath);
     }
     else if (url.StartsWith("https://detail.tmall.com/item.htm?") || url.StartsWith("https://world.tmall.com/item/"))
     {
         driver.Navigate().GoToUrl(url);
         if (!login)
         {
             Console.WriteLine("Please login TMall");
             Console.ReadKey();
             login = true;
         }
         var priceText = "";
         var title     = "";
         var storeName = "";
         try
         {
             priceText = driver.FindElement(By.ClassName("tm-fcs-panel")).Text;
             title     = driver.FindElement(By.ClassName("tb-detail-hd")).FindElement(By.TagName("h1")).Text;
             storeName = driver.FindElement(By.ClassName("shopLink")).Text;
         }
         catch (NoSuchElementException e)
         {
             Console.WriteLine(e.Message);
         }
         if (String.IsNullOrWhiteSpace(priceText))
         {
             return(null);
         }
         var price = ParsePrice(priceText, url);
         price.sourceUrl = url;
         price.storeName = storeName;
         price.ItemName  = title;
         price.Calculate();
         Console.WriteLine(url);
         Console.WriteLine(priceText);
         Console.WriteLine(title);
         Console.WriteLine(JsonConvert.SerializeObject(price));
         return(price);
     }
     return(null);
 }
示例#2
0
        public Price CheckPrice(Dictionary <string, string> it)
        {
            try
            {
                if (it == null)
                {
                    return(null);
                }
                if (jdCount > 10)
                {
                    this.driver.Quit();
                    this.driver = new FirefoxDriver();
                    jdCount     = 0;
                }
                if (Helper.ToUrl(driver, it["smzdmProduct"]))
                {
                    Console.WriteLine(driver.Url);
                    try
                    {
                        var url = "";
                        driver.FindElement(By.ClassName("new-baike-card"));
                        if (Helper.ToUrl(driver, it["smzdmGo"]))
                        {
                            Console.WriteLine(driver.Url);
                            url = driver.Url;
                            var price = new Price();
                            if (driver.Url.StartsWith("https://product.suning.com/") || driver.Url.StartsWith("http://product.suning.com/"))
                            {
                                price = SUNINGPriceParser.ExtractPrice(driver);
                                if (price != null)
                                {
                                    price.Calculate();
                                    if (price.finalPrice <= 0)
                                    {
                                        Console.WriteLine("Fail to process SUNING item, Skip");
                                        return(null);
                                    }
                                }
                            }
                            else if (driver.Url.StartsWith("https://re.jd.com/cps/item/") || driver.Url.StartsWith("http://re.jd.com/cps/item/"))
                            {
                                jdCount++;
                                driver.FindElement(By.ClassName("gobuy")).Click();
                                Console.WriteLine("Wait 5s for redirect from re.jd.com");
                                Thread.Sleep(5000);
                                if (driver.Url.StartsWith("https://passport.jd.com/"))
                                {
                                    var parts = driver.Url.Split("?=".ToCharArray());
                                    foreach (var p in parts)
                                    {
                                        if (p.StartsWith("https://item.jd.com/"))
                                        {
                                            driver.Navigate().GoToUrl(p);
                                            price = JDPriceParser.ExtractPrice(driver);

                                            break;
                                        }
                                    }
                                    //driver.Close();
                                }
                            }
                            else if (driver.Url.StartsWith("https://item.jd.com/") || driver.Url.StartsWith("http://item.jd.com/"))
                            {
                                jdCount++;
                                price = JDPriceParser.ExtractPrice(driver);
                                //driver.Close();
                                //Console.WriteLine("close page2");
                            }
                            //if(driver.Url.StartsWith("https://item.jd.com/") || driver.Url.StartsWith("http://item.jd.com/"))
                            //{
                            //    price = JDPriceParser.ExtractPrice();
                            //}
                            price.SmzdmGoodPrice = double.Parse(it["smzdmGoodPrice"]);
                            price.sourceUrl      = url;
                            price.SmzdmItemTitle = it["smzdmItemTitle"];
                            price.SmzdmGoUrl     = it["smzdmGo"];

                            Console.WriteLine("Verfied " + price.sourceUrl + " " + price.SmzdmGoodPrice);

                            return(price);
                        }
                    }
                    catch (NoSuchElementException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            catch (WebDriverException e)
            {
                Console.WriteLine("deal finder " + e.Message);
                return(null);
            }
            return(null);
        }