private static void pollingEmail(string connString) { Boolean success = false; WebDriverSettingInfo webDriverSetting = new WebDriverSettingInfo(hideCommand: true, hideBrowser: false); List <HotelInfo> hotels = DataOperation.GetHotels(connString); display($"polling Email: {hotels.Count}:", isWriteLine: true, addTime: true); ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: webDriverSetting.HideBrowser, hideCommand: webDriverSetting.HideCommand, isMaximized: true); Int32 count = 0; foreach (HotelInfo hotel in hotels) { display($"[{hotel.Id}] {hotel.Name} -> ", isWriteLine: false, addTime: true); try { driver.Navigate().GoToUrl("https://www.google.ca"); IWebElement element; element = driver.FindElement(By.Id("lst-ib")); element.SendKeys($"{hotel.Name}, {hotel.Region}"); element.SendKeys(Keys.Return); element = driver.FindElement(By.XPath("//a[@class='ab_button' and text()='Website']")); element.Click(); hotel.Update(driver); } catch (Exception ex) { hotel.Comments = ex.Message; } success = DataOperation.AddHotel(connString, hotel); ++count; display($" [Done]", isWriteLine: true); } driver.Quit(); }
internal static void PollingSeller(string connString) { Boolean success = true; String code = "C"; try { _WebDriverSetting = new WebDriverSettingInfo(true, false); Utilities.Utilities.Log(message: "Polling Seller Start ... ", isWriteLine: false, addTime: true); List <CategoryInfo> categories = DataOperation.GetCategory(connString); Utilities.Utilities.Log(message: $"[{categories.Count}]", isWriteLine: true); ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: _WebDriverSetting.HideBrowser, hideCommand: _WebDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 3, 0)); foreach (CategoryInfo category in categories.Where(cat => !String.IsNullOrEmpty(cat.ToSellersUrl))) { success = false; pollingSeller(connString, $"{category.Name}", driver, category, category.ToSellersUrl, true); Dictionary <String, String> urlList = getUrlList(driver, category.ToSellersUrl); foreach (String key in urlList.Keys) { pollingSeller(connString, $"{category.Name}.{key}", driver, category, urlList[key], false); } category.Completed = true; category.Id = DataOperation.UpdateCategory(connString, category); } driver.Quit(); } catch (System.Exception ex) { Utilities.Utilities.Log(message: $"[Error]{ex.Message}", feedLine: true, isWriteLine: true, addTime: true); } }
internal static void PollingProduct(String connString, String code) { Boolean success = true; try { _WebDriverSetting = new WebDriverSettingInfo(true, false); Utilities.Utilities.Log(message: "Polling Product Start ... ", isWriteLine: false, addTime: true); List <ProductToSearchInfo> productsToSearch = DataOperation.GetProductToSearch(connString); Utilities.Utilities.Log(message: $"[{productsToSearch.Count}]", isWriteLine: true); ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: _WebDriverSetting.HideBrowser, hideCommand: _WebDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 1)); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1); foreach (ProductToSearchInfo productToSearch in productsToSearch) { success = false; Utilities.Utilities.Log(message: $"[{productToSearch.ProductName}] : ", isWriteLine: false, addTime: true); if (String.IsNullOrEmpty(productToSearch.Url)) { productToSearch.Url = getProductUrl(productToSearch); } driver.Navigate().GoToUrl(productToSearch.Url); String metadata = driver.PageSource; Int32 totalPages = getPage(driver, "//div[@id='pagn']/span[last()-1]"); Int32 page = getPage(driver, "//div[@id='pagn']/span[count(*)=0]"); do { Utilities.Utilities.Log(message: $"[{page}]", isWriteLine: false, addTime: false); ReadOnlyCollection <IWebElement> elements = null; if (driver.GetElements("//ul[@id='s-results-list-atf']/li", ref elements)) { Int32 index = 0; foreach (IWebElement element in elements) { ProductInfo product = new ProductInfo(driver, element, page, ++index, false); if (!String.IsNullOrEmpty(product.ProductId)) { DataOperation.UpdateProduct(connString, product); } Utilities.Utilities.Log(message: $".", isWriteLine: false, addTime: false); } } else { } } while (page < totalPages && gotoNextPage(driver, ref page)); success = DataOperation.UpdateProductToSearchStatus(connString, productToSearch); Utilities.Utilities.Log(message: $"[Done]", isWriteLine: true, addTime: false); } driver.Quit(); } catch (System.Exception ex) { Utilities.Utilities.Log(message: $"[Error]{ex.Message}", feedLine: true, isWriteLine: true, addTime: true, isError: true); } }
private static void pollingHotel(String connString) { WebDriverSettingInfo webDriverSetting = new WebDriverSettingInfo(hideCommand: true, hideBrowser: false); Boolean success = false; String baseUrl = "https://ca.hotels.com/search.do?resolved-location=CITY:{id}:UNKNOWN:UNKNOWN&f-star-rating=3,2&destination-id={id}&q-destination={region}&q-check-in={checkin}&q-check-out={checkout}&q-rooms=1&q-room-0-adults=2&q-room-0-children=0"; baseUrl = baseUrl.Replace("{checkin}", "2018-09-25"); baseUrl = baseUrl.Replace("{checkout}", "2018-09-26"); Dictionary <String, String> cities = new Dictionary <string, string>() { { "170961", "Kitchener, Ontario, Canada" }, { "1633548", "Hamilton, Ontario" }, { "169995", "Quebec, Quebec, Canada" }, { "169714", "Ottawa, Ontario, Canada" }, { "167228", "Edmonton, Alberta, Canada" }, { "169003", "Calgary, Alberta, Canada" }, { "169712", "Vancouver, British Columbia, Canada" }, { "169716", "Montreal, Quebec, Canada" }, { "1636865", "Toronto, Ontario, Canada" }, { "170165", "Winnipeg, Manitoba, Canada" } }; ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: webDriverSetting.HideBrowser, hideCommand: webDriverSetting.HideCommand, isMaximized: true); foreach (String key in cities.Keys) { display($"{cities[key]} -> ", isWriteLine: false, addTime: true); String url = baseUrl.Replace("{id}", key); url = url.Replace("{region}", cities[key]); driver.Navigate().GoToUrl(url); Int32 count = scrollToBottom(driver, "info unavailable-info", 2, true); IReadOnlyCollection <IWebElement> elements = driver.FindElementsByXPath("//ol/li"); display($" pages: [{count}] -> [{elements.Count}]", isWriteLine: false); count = 0; foreach (IWebElement element in elements) { HotelInfo hotel = new HotelInfo(driver, element, cities[key]); if (!String.IsNullOrEmpty(hotel.Name)) { success = DataOperation.AddHotel(connString, hotel); ++count; if (count % 10 == 0) { display($".", isWriteLine: false); } } } display($" Done[{count}]", isWriteLine: true); } driver.Quit(); }
internal static void PollingCategory(string connString, string code) { Boolean success = true; _WebDriverSetting = new WebDriverSettingInfo(true, false); Utilities.Utilities.Log(message: "Polling Categories Start ... ", isWriteLine: false, addTime: true); try { WebsiteInfo website = DataOperation.GetWebsite(connString, code); ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: _WebDriverSetting.HideBrowser, hideCommand: _WebDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 3, 0)); driver.Navigate().GoToUrl(website.Url); IReadOnlyCollection <IWebElement> elements = wait.Until(d => d.FindElements(By.XPath("//div[@class='fsdDeptBox']"))); if (elements != null) { Utilities.Utilities.Log(message: $"[{elements.Count}]", isWriteLine: true); foreach (IWebElement element in elements) { CategoryInfo parent = new CategoryInfo(element); parent.Id = DataOperation.UpdateCategory(connString, parent); IReadOnlyCollection <IWebElement> eles = element.FindElements(By.XPath(".//div[@class='fsdDeptCol']/a")); if (eles != null) { Utilities.Utilities.Log(message: $"[{parent.Name}] [{eles.Count}] -> ", isWriteLine: false, addTime: true); Int32 count = 0; foreach (IWebElement ele in eles) { CategoryInfo category = new CategoryInfo("", parent, ele); if (success = category.HasError) { category.Id = DataOperation.UpdateCategory(connString, category); if (success = category.Id > 0) { ++count; } } Utilities.Utilities.Log(message: success ? $"." : $"X", isWriteLine: false, addTime: false); } Utilities.Utilities.Log(message: $" [{count}] [Done]", isWriteLine: true, addTime: false); } } } } catch (System.Exception ex) { Utilities.Utilities.Log(message: "Polling Categories Start ... ", feedLine: true, isWriteLine: true, addTime: true); } }
public static void PollingCategoryUrls(String connString, String code) { Console.Clear(); _WebDriverSetting = new WebDriverSettingInfo(hideCommand: true, hideBrowser: true); Boolean success = false; Int32 totalCategory = 0; Int32 countCategory = 0; Int32 totalSupplierAdded = 0; Int64 totalTicks = 0; Random random = new Random(); List <SupplierCategoryInfo> list = DataOperation.GetCategoryList(connString, code); totalCategory = list.Count; display(String.Format("Polling Suppliers Start ... [{0}]", totalCategory), true, true); try { ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: _WebDriverSetting.HideBrowser, hideCommand: _WebDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 3, 0)); foreach (SupplierCategoryInfo category in list) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); display(String.Format("[{0}/{1}] - {2} ... ", ++countCategory, totalCategory, category.Name), false, true); _CursorPosition = new Point(Console.CursorTop, Console.CursorLeft); success = pollingSupplierUrls(connString, driver, wait, category); stopWatch.Stop(); totalTicks += stopWatch.Elapsed.Ticks; totalSupplierAdded += category.CountAdded; Int64 countRemaining = (Int64)(totalSupplierAdded / countCategory) * (totalCategory - countCategory); Int64 averageTicks = totalTicks / (totalSupplierAdded == 0 ? 1 : totalSupplierAdded); TimeSpan timeSpan = new TimeSpan(averageTicks * countRemaining); display(message: $" [{timeSpan:d\\.hh\\:mm\\:ss}]", isWriteLine: true, addTime: false); } driver.Quit(); display(String.Format("Completed [{0}]", success), true, true); } catch (System.Exception ex) { display(String.Format("[Webdriver] ERROR: {0}", ex.Message), true, true); } display(String.Format("*****Polling Suppliers End. [{0}]", totalCategory), true, true); }
internal static void PollingSellerDetail(string connString) { Boolean success = true; String code = "C"; try { _WebDriverSetting = new WebDriverSettingInfo(true, true); Utilities.Utilities.Log(message: "Polling Seller dey=tails Start ... ", isWriteLine: false, addTime: true); List <SellerInfo> sellers = DataOperation.GetSeller(connString); Utilities.Utilities.Log(message: $"[{sellers.Count}]", isWriteLine: true); ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: _WebDriverSetting.HideBrowser, hideCommand: _WebDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 3, 0)); foreach (SellerInfo seller in sellers) { success = false; Utilities.Utilities.Log(message: $"[{seller.Name}] : ", isWriteLine: false, addTime: true); driver.Navigate().GoToUrl($"https://www.amazon.com/sp?seller={seller.SellerId}"); if (driver.PageSource.Contains("feedback-summary-table")) { IReadOnlyCollection <IWebElement> elements = driver.FindElements(By.XPath("//table[@id='feedback-summary-table']/tbody/tr[5]/td[@class='a-text-right']")); if (elements != null && elements.Count > 0) { seller.Update(elements.ToList <IWebElement>()); success = true; } } else { seller.Update(null); } seller.Id = DataOperation.UpdateSeller(connString, seller); success &= seller.Id > 0; Utilities.Utilities.Log(message: success ? $"[Done]" : $"[X]", isWriteLine: true, addTime: false); } driver.Quit(); } catch (System.Exception ex) { Utilities.Utilities.Log(message: $"[Error]{ex.Message}", feedLine: true, isWriteLine: true, addTime: true); } }
public static void PollingSuppliersFromUrl(String connString) { WebDriverSettingInfo webDriverSetting = new WebDriverSettingInfo(true, true); Boolean success = false; Int32 totalCategory = 0; Int32 countCategory = 0; Random random = new Random(); List <SupplierUrlInfo> list = DataOperation.GetSupplierUrls(connString); totalCategory = list.Count; display(String.Format("Polling Suppliers from URL Start ... [{0}]", totalCategory), true, true); try { ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: webDriverSetting.HideBrowser, hideCommand: webDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 3, 0)); foreach (SupplierUrlInfo supplierUrl in list) { display(String.Format("[{0}/{1}] - [{2}] {3} [{4}] Processing ...", ++countCategory, totalCategory, supplierUrl.Id, supplierUrl.CategoryName, supplierUrl.Tries), false, true); try { SupplierInfo supplier = new SupplierInfo(driver, wait, supplierUrl.ProfileUrl, new SupplierCategoryInfo(supplierUrl.CategoryId, supplierUrl.CategoryName, supplierUrl.CategoryLevel)); if (!supplier.HasError) { success = DataOperation.UpdateSupplier(connString, supplier); } success = DataOperation.UpdateSupplierUrlStatus(connString, supplierUrl, supplier); display(String.Format(" [{0}]", supplier.HasError ? "XX" : supplier.CompanyId), true, false); } catch (System.Exception ex) { Console.WriteLine("[Post] ERROR: {0}", ex.Message); } } driver.Quit(); } catch (System.Exception ex) { Console.WriteLine("[Webdriver] ERROR: {0}", ex.Message); } Console.WriteLine("Polling Suppliers End. [{0}]", totalCategory); }
internal static void PollingCategory(string connString) { Boolean success = true; String code = String.Empty; try { _WebDriverSetting = new WebDriverSettingInfo(true, false); Utilities.Utilities.Log(message: "Polling Sellers for Category Start ... ", isWriteLine: false, addTime: true); List <CategoryInfo> categories = DataOperation.GetCategory(connString); Utilities.Utilities.Log(message: $"[{categories.Count}]", isWriteLine: true); ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: _WebDriverSetting.HideBrowser, hideCommand: _WebDriverSetting.HideCommand); WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 3, 0)); foreach (CategoryInfo parent in categories) { Int32 count = 0; driver.Navigate().GoToUrl(parent.Url); if (!pollingCategorySellerB(connString, parent, driver, ref count) && !pollingCategorySellerA(connString, parent, driver, ref count) ) { } Utilities.Utilities.Log(message: $" [{count}] [Done]", isWriteLine: true, addTime: false); IWebElement element = driver.GetElement("//h4[@class='a-size-small a-spacing-mini a-color-base a-text-bold' and text()='Seller']/following-sibling::ul/li/span/a"); if (element != null) { parent.ToSellersUrl = element.GetValue("", "href"); } parent.Completed = true; parent.Id = DataOperation.UpdateCategory(connString, parent); } driver.Quit(); } catch (System.Exception ex) { Utilities.Utilities.Log(message: $"[Error]{ex.Message}", feedLine: true, isWriteLine: true, addTime: true); } }
public static void SendingAndPolling(String connString, string[] args) { WebDriverSettingInfo webDriverSetting = new WebDriverSettingInfo(hideCommand: false, hideBrowser: false); Int32 totalAccount = 1; Boolean isAll = true; if (args.Length > 0) { totalAccount = Convert.ToInt32(args[0]); if (args.Length == 2) { isAll = args[1].ToBoolean(); } } String status = Utilities.Utilities.GetCurrentMethodName(); Boolean success = false; Random random = new Random(); display(message: $"[{status}] Sending And Polling Start ... [{totalAccount}]", isWriteLine: true, addTime: true, feedLine: true); Int32 count = 1; while (count <= totalAccount) { try { ChromeDriver driver = Utilities.WebDriverExtension.GetChromeDriver(hideBrowser: webDriverSetting.HideBrowser, hideCommand: webDriverSetting.HideCommand, isMaximized: true); if (driver != null) { SettingsInfo setting = DataOperation.GetSetting(connString); //setting.Email = "*****@*****.**"; //setting.Password = "******"; display(String.Format("[{0}/{1}] [{2}] ....", count, totalAccount, setting.Email), false, true); if (alibabaLogin(driver, connString, setting, random.Next(4000, 6000))) { ++count; success = DataOperation.UpdateSettingPostStatus(connString, setting); if (sendingMessages(driver, random, connString, setting)) { if (isAll) { success = pollingBusinessCardSent(driver, random, connString, setting); success = pollingBusinessCardReceived(driver, random, connString, setting); } } else { display($"[{status}] Failed with email verification.", true, true); } } else { display($"[{status}] Login Failed.", true, true); } } driver.Quit(); if (_Stop) { break; } } catch (System.Exception ex) { display($"[{status}] ERROR: {ex.Message}", true, true); } } }