static async Task Share(DealPublisher publisher, Option opt, string taskPath, string statusPath) { publisher.driver.Navigate().GoToUrl(@"https://www.smzdm.com/baoliao/?old"); Thread.Sleep(5000); publisher.ReadInfo(); if (publisher.baoLiaoLeft != 0) { DealFinder finder = new DealFinder(opt); while (publisher.baoLiaoLeft != 0) { String content; using (StreamReader reader = File.OpenText(taskPath)) { content = await reader.ReadToEndAsync(); } content = ProcessTask(content, opt, out Tuple <string, int> task); await WriteFileAsync(taskPath, content); Console.WriteLine("Write done."); opt.Topic = task.Item1; Console.WriteLine(opt.Topic); Console.Title = opt.username + " " + task.Item1 + task.Item2 + " " + publisher.baoLiaoLeft; var pageUrl = Helper.GetTopicUrl(opt.Topic, task.Item2.ToString()); if (pageUrl == null) { return; } var exceptionCount = 0; while (exceptionCount < 5) { try { FindDealAndPublish(opt, pageUrl, finder, publisher); break; } catch (Exception e1) { MyLogger.LogWarnning(e1.Message); exceptionCount += 1; } } if (exceptionCount >= 5) { break; } } finder.driver.Quit(); } }
static void FindDealAndPublish(Option option, string pageUrl, DealFinder dealFinder, DealPublisher publisher) { var smzdmItemList = new List <Dictionary <string, string> >(); dealFinder.driver.Navigate().GoToUrl(pageUrl); var items = dealFinder.driver.FindElements(By.ClassName("z-feed-content")).ToList(); foreach (IWebElement item in items) { var it = dealFinder.GetSmzdmItem(item); if (it != null) { smzdmItemList.Add(it); } } Console.WriteLine("Collected good price count " + smzdmItemList.Count); foreach (var it in smzdmItemList) { var price = dealFinder.CheckPrice(it); if (price != null) { price.Calculate(); var goodPrice = price.SmzdmGoodPrice; var sourceUrl = price.sourceUrl; var continueSubmit = publisher.PasteItemUrl(sourceUrl, 0, option.waitBaoliao, option.baoLiaoStopNumber); if (continueSubmit) { Console.WriteLine("Continue to submit."); publisher.SubmitBaoLiao(option.descriptionMode, goodPrice, 0.0, sourceUrl, option.PriceRate, 0.0, price); } if (publisher.baoLiaoLeft == 0) { Console.WriteLine("BaoLiao left 0, break."); break; } Console.WriteLine("Move to next item"); } } Console.WriteLine(option.Topic + " " + pageUrl + " Task Finished"); Console.WriteLine("baoliao left " + publisher.baoLiaoLeft); }