private void bt_saveCookie_Click(object sender, EventArgs e) { if (_driver == null) { lb_msg.Text = "不存在cookie"; return; } try { CookieContainer cookieContainer = new CookieContainer(); //获取cookies var cookies = _driver.Manage().Cookies.AllCookies; for (int i = 0; i < cookies.Count; i++) { var tempCookie = new System.Net.Cookie() { Domain = cookies[i].Domain, Expires = cookies[i].Expiry ?? DateTime.MaxValue, HttpOnly = cookies[i].IsHttpOnly, Name = cookies[i].Name, Path = cookies[i].Path, Secure = cookies[i].Secure, Value = cookies[i].Value }; _cookieContainers.Add(tempCookie); cookieContainer.Add(tempCookie); } FileComm.WriteFile(StaticResources.COOKIE_FILE_PATH, Encoding.UTF8.GetBytes(FormatterComm.Serialize(cookieContainer))); lb_msg.Text = "保存成功"; } catch (Exception ex) { rtb_errorMsg.Text = ex.Message + "\r\n" + rtb_errorMsg.Text; } }
public void DownImg() { _thread03 = new Thread(() => { HttpComm httpComm = new HttpComm(); int count = 0; while (true) { if (_ImgUrls.TryDequeue(out var img)) { var url = img.Item1; var path01 = string.Format("{0}-{1}", img.Item2.question.id, img.Item2.question.title.ToDirectoryPath() ); var path02 = string.Format("{0}-{1}-{2}", img.Item2.id, img.Item2.author.name.ToDirectoryPath(), img.Item2.CreatedTime ); var fullPath = string.Empty; var fileNname = string.Empty; if (cb_isClassify.Checked) { fullPath = Path.Combine(path01, path02); fileNname = Guid.NewGuid().ToString() + Path.GetExtension(url); } else { fullPath = path01; fileNname = path02 + Guid.NewGuid().ToString() + Path.GetExtension(url); } if (!System.IO.Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } var path = Path.Combine(fullPath, fileNname); try { httpComm.Request(url); var byts = httpComm.ResponseBts; FileComm.WriteFile(path, byts); Invoke(new MethodInvoker(delegate() { rtb_downImg.Text = "DownImg:" + url + "\r\n" + rtb_downImg.Text; })); } catch (Exception ex) { Invoke(new MethodInvoker(delegate() { rtb_errorMsg.Text = "DownImg:" + ex.Message + "\r\n" + rtb_errorMsg.Text; })); } } else { Invoke(new MethodInvoker(delegate() { rtb_downImg.Text = "DownImg:" + (++count).ToString() + "\r\n" + rtb_downImg.Text; })); Thread.Sleep(1000); } } }); _thread03.Start(); }