private void WaitForDownload(SeDo se, string id) { int count = 0; long lastSize = 0; while (true) { DirectoryInfo di = new DirectoryInfo(Form1.Instance.downloadDir + "/" + id); var files = di.GetFiles(); if (files.Length == 0) { count++; } else if (GetDownloadName(id).EndsWith(".crdownload")) { count++; } else if (new FileInfo(files[0].FullName).Length == lastSize) { count += 30; } else { count = 0; } if (count > 100) { return; } lastSize = new FileInfo(files[0].FullName).Length; Console.WriteLine("download " + count + " " + lastSize); Sleep(1); } }
public static SeDo Get(string id) { if (!dict.ContainsKey(id)) { SeDo se = new SeDo(id); dict.Add(id, se); } return(dict[id]); }
private static void Release(string id) { SeDo.Release(id); if (!m_dict.ContainsKey(id)) { return; } m_dict.Remove(id); }
private bool CheckClickPopWindow(SeDo se, string id, string btnText) { var wind = se.FindId(id); if (wind != null && wind.GetAttribute("style").Contains("display: block;")) { var btn = wind.FindElement(By.XPath("//*[@id='" + id + "']//a[text()='" + btnText + "']")); btn.Click(); ALog("Click -> " + id + " " + btnText); Sleep(3); return(true); } return(false); }
private bool UseSeDo() { try { se = SeDo.Get(id); } catch (Exception e) { if (e.Message.Contains("任务队列已满")) { Fail(e.Message); } else { Fail("打开Selenium时出错~\n" + e.Message); } return(false); } return(true); }
private void Application_ApplicationExit(object sender, EventArgs e) { SeDo.DisposeAll(); }
public static void AutoLogin(SeDo se, Action <bool> callback, bool forceLogin = false) { TaskDo.Execute(() => { try { if (forceLogin) { se.GoToUrl("https://passport.csdn.net/account/logout"); Sleep(1); se.GoToUrl("https://passport.csdn.net/login"); } else { se.GoToUrl("https://i.csdn.net"); } Sleep(2); if (forceLogin || !se.CurUrl().StartsWith("https://i.csdn.net")) { if (string.IsNullOrEmpty(Form1.Instance.account) || string.IsNullOrEmpty(Form1.Instance.password)) { throw new Exception("账号或密码为空"); } se.FindText("帐号登录").Click(); Sleep(0.5f); se.FindId("all").Click(); Sleep(0.5f); se.FindId("all").SendKeys(Form1.Instance.account); Sleep(0.5f); se.FindClass("main-login").Click(); Sleep(0.5f); se.FindId("password-number").Click(); Sleep(0.5f); se.FindId("password-number").SendKeys(Form1.Instance.password); Sleep(0.5f); se.FindClass("main-login").Click(); Sleep(0.5f); se.FindClass("btn btn-primary").Click(); Sleep(2); se.GoToUrl("https://i.csdn.net"); Sleep(2); if (se.CurUrl().StartsWith("https://i.csdn.net")) { callback.Invoke(true); } else { callback.Invoke(false); } } else { callback.Invoke(true); } } catch (Exception e) { ALog(e.Message); callback.Invoke(false); } }); }
public static void ForceLogin(SeDo se, Action <bool> callback) { AutoLogin(se, callback, true); }