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YW5odWEucXBpYy5jblwvb3BlcmF0aW9uXC8wXC8xM18wOV81Ml84ZWJjZTJkZmJhMzZhZDhlYTA2YjEyODRkNzY1Mzc0Nl8xNTEwNTM3OTM3NDY2LmpwZ1wvMCIsInVybCI6Imh0dHA6XC9cL2FjLnFxLmNvbVwvQ29taWNWaWV3XC9pbmRleFwvaWRcLzYyNjg1MFwvY2lkXC8yIiwid2lkdGgiOiI2NTAiLCJoZWlnaHQiOiIxMTAifX0sImFydGlzdCI6eyJhdmF0YXIiOiJodHRwOlwvXC9xNC5xbG9nby5jblwvZz9iPXFxJms9d2g1c0ZOazAzUDV6RmlhOGljdGQ4ZW13JnM9NjQwJnQ9MTQ4MzMzOTY3NSIsIm5pY2siOiJcdTc3ZTVcdTk3ZjNcdTc5ZmJcdTUyYThcdTY1NzBcdTViNTciLCJ1aW5DcnlwdCI6IlVUSk1kVkpCZDAxTlFrSkVibGhzWmpOWlJqRjBaejA5In19"; //var ss = DecodeHelper.QQPageDecode(keystr.Substring(1)); //var tt = JsonHelper.DeserializeJsonToObject<QQ_Page_Api>(ss); //var redis = new RedisProxy(); //try //{ // redis.HashSet("QQ_Chapter", "185158", "185157"); //} //catch (Exception ex) //{ // throw; //} //var login_key = redis.Get<QQ_Login_Key>("QQ_1434299101"); DateTime dt = DateTime.Now; string ticks = dt.Ticks.ToString(); string shortdate = dt.ToString("yyyy-MM-dd"); string yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd"); IQuery <Chapter> cpq = dbcontext.Query <Chapter>();//x.comicid == "1_622585" IQuery <VIPFreeComic> vfcq = dbcontext.Query <VIPFreeComic>(); List <Chapter> cplst; if (QQChapterTotal > 0) { cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip == "0" && x.Id % QQChapterTotal == QQChapterIndex).Take(200).ToList(); } else { cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip == "0").Take(200).ToList(); } List <int> ids = cplst.Select(x => x.Id).ToList(); dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter() { ticks = ticks, downstatus = DownChapter.处理完链接, modify = dt }); List <Chapter> chapterlst = new List <Chapter>(); foreach (var cp in cplst) { try { //Dictionary<string, string> headers = new Dictionary<string, string>() //{ // {"Cookie","uin=o1434299101; skey="+login_key.skey+";" } //}; var imgdata = _helper.Get(cp.chapterurl, Encoding.GetEncoding("UTF-8"), null, "", null, "", null, "application/x-www-form-urlencoded; charset=UTF-8"); Regex rex = new Regex("var DATA = '(?<key1>.*?)',"); Match match = rex.Match(imgdata); string key = match.Groups["key1"].Value; if (string.IsNullOrEmpty(key)) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; cp.ticks = ticks; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = "DATA解析失败"; err = dbcontext.Insert(err); continue; } var s = DecodeHelper.QQPageDecode(key.Substring(1)); var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s); if (t.chapter.canRead) { List <Page> pglst = new List <Page>(); for (int i = 0; i < t.picture.Count; i++) { pglst.Add(new Page() { chapterid = cp.chapterid, modify = dt, shortdate = shortdate, sort = i + 1, source = cp.source, pagelocal = "", ticks = ticks, pagesource = t.picture[i].url }); } cp.isvip = "0"; cp.ticks = ticks; cp.downstatus = DownChapter.处理完链接; cp.modify = dt; dbcontext.Update(cp); dbcontext.BulkInsert(pglst); } else { List <VIPFreeComic> vfclst = vfcq.Where(x => x.source == Source.QQ && x.comicid == cp.comicid).ToList(); cp.isvip = vfclst.Count == 0 ? "1" : "0"; cp.ticks = ticks; cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); } } catch (Exception ex) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; cp.ticks = ticks; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } }
public void Execute(IJobExecutionContext context) { DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); string yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd"); IQuery <Chapter> cpq = dbcontext.Query <Chapter>(); List <Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接).Take(200).ToList(); List <int> ids = cplst.Select(x => x.Id).ToList(); dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter() { downstatus = DownChapter.处理完链接, modify = dt }); List <Chapter> chapterlst = new List <Chapter>(); foreach (var cp in cplst) { try { string chapterpage = cp.chapterurl.Replace("http://ac.qq.com", ""); var imgdata = _helper.Get(null, chapterpage); Regex rex = new Regex("var DATA = '(?<key1>.*?)',"); Match match = rex.Match(imgdata); string key = match.Groups["key1"].Value; if (string.IsNullOrEmpty(key)) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(dt); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = "DATA解析失败"; err = dbcontext.Insert(err); continue; } var s = DecodeHelper.QQPageDecode(key.Substring(1)); var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s); if (t.chapter.vipStatus == 1) { List <Page> pglst = new List <Page>(); for (int i = 0; i < t.picture.Count; i++) { pglst.Add(new Page() { chapterid = cp.Id, modify = dt, shortdate = shortdate, sort = i + 1, source = cp.source, pagelocal = "", pagesource = t.picture[i].url }); } dbcontext.Update(cp); dbcontext.BulkInsert(pglst); } } catch (Exception ex) { logger.Error(ex.Message); cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } }
public void Execute(IJobExecutionContext context) { //logger.Info("QQ_page vip begin"); //string isStart = "IsStartBuyQQ".ValueOfAppSetting(); //if (isStart != null && isStart.Equals("1")) { DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); string yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd"); IQuery <Chapter> cpq = dbcontext.Query <Chapter>();//x.comicid == "1_524356" IQuery <PageHis> phisq = dbcontext.Query <PageHis>(); //List<Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.待处理链接 && x.isvip.Equals("1")).Take(200).ToList(); List <Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.完图片 && x.isvip.Equals("1")).Take(200).ToList(); List <int> ids = cplst.Select(x => x.Id).ToList(); dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter() { downstatus = DownChapter.处理中, modify = dt }); List <Chapter> chapterlst = new List <Chapter>(); Regex rex = new Regex("var DATA = '(?<key1>.*?)',"); string errMsg; foreach (var cp in cplst) { try { IQuery <PageHis> cpHis = phisq.Where(x => x.chapterid == cp.chapterid); if (cpHis != null && cpHis.Count() > 0) { List <PageHis> cpHisList = cpHis.ToList(); List <Page> pglst = new List <Page>(); foreach (var page in cpHisList) { pglst.Add(new Page() { chapterid = page.chapterid, modify = dt, shortdate = shortdate, sort = page.sort, source = page.source, pagelocal = "", pagesource = page.pagesource }); } cp.downstatus = DownChapter.处理完链接; cp.modify = dt; dbcontext.Update(cp); dbcontext.BulkInsert(pglst); logger.Info("QQ_page vip syn history sucess:id=" + cp.Id); } else { errMsg = string.Empty; selenium.Navigate().GoToUrl(cp.chapterurl); IList <IWebElement> frames = selenium.FindElements(By.TagName("iframe")); IWebElement controlPanelFrame = null; foreach (var frame in frames) { if (frame.GetAttribute("id") == "iframeAll") { controlPanelFrame = frame; break; } } if (controlPanelFrame != null && controlPanelFrame.Displayed == true) //QQ登录 { try { selenium.SwitchTo().Frame(controlPanelFrame); IReadOnlyCollection <IWebElement> switchtoElement = selenium.FindElements(By.Id("switcher_plogin")); if (switchtoElement != null && switchtoElement.Count > 0 && switchtoElement.First().Displayed == true) { switchtoElement.First().Click(); selenium.FindElement(By.Id("u")).Clear(); selenium.FindElement(By.Id("u")).SendKeys("3283360259"); selenium.FindElement(By.Id("p")).Clear(); selenium.FindElement(By.Id("p")).SendKeys("xxxttt5544"); //selenium.FindElement(By.Id("u")).Clear(); //selenium.FindElement(By.Id("u")).SendKeys("1434299101"); //selenium.FindElement(By.Id("p")).Clear(); //selenium.FindElement(By.Id("p")).SendKeys("zhangyin123"); selenium.FindElement(By.Id("login_button")).Click(); } selenium.SwitchTo().DefaultContent(); } catch (Exception ex) { errMsg = "QQ 登录失败:" + ex.Message; logger.Error(errMsg); } } selenium.Navigate().GoToUrl("http://ac.qq.com/Home/buyList"); ICookieJar listCookie = selenium.Manage().Cookies; // IList<Cookie> listCookie = selenuim.Manage( ).Cookies.AllCookies;//只是显示 可以用Ilist对象 //显示初始Cookie的内容 Console.WriteLine("--------------------"); Console.WriteLine($"当前Cookie集合的数量:\t{listCookie.AllCookies.Count}"); for (int i = 0; i < listCookie.AllCookies.Count; i++) { Console.WriteLine($"Cookie的名称:{listCookie.AllCookies[i].Name}"); Console.WriteLine($"Cookie的值:{listCookie.AllCookies[i].Value}"); Console.WriteLine($"Cookie的所在域:{listCookie.AllCookies[i].Domain}"); Console.WriteLine($"Cookie的路径:{listCookie.AllCookies[i].Path}"); Console.WriteLine($"Cookie的过期时间:{listCookie.AllCookies[i].Expiry}"); Console.WriteLine("-----"); } frames = selenium.FindElements(By.TagName("iframe")); IWebElement checkVipFrame = null; foreach (var frame in frames) { if (frame.GetAttribute("id") == "checkVipFrame") { checkVipFrame = frame; break; } } if (checkVipFrame != null && checkVipFrame.Displayed == true) { try { //自动购买 selenium.SwitchTo().Frame(checkVipFrame); IReadOnlyCollection <IWebElement> checkAutoElement = selenium.FindElements(By.Id("check_auto_next")); IReadOnlyCollection <IWebElement> singlBbuyElement = selenium.FindElements(By.ClassName("single_buy")); if (checkAutoElement != null && singlBbuyElement != null && checkAutoElement.Count > 0 && singlBbuyElement.Count > 0 && checkAutoElement.First().Displayed == true) { if (singlBbuyElement.First().Text.IndexOf("点券不足") > -1) { //列表中未成功购买的数据还原成待处理 dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter() { downstatus = DownChapter.待处理链接, modify = dt }); ////关闭购买,等待修改配置 //"IsStartBuyQQ".SetAppSettingValue("0"); if (isHasMoney) { Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = "点券不足,请去充值!"; err = dbcontext.Insert(err); } isHasMoney = false; //Thread.Sleep(3600000); continue; } else { isHasMoney = true; } checkAutoElement.First().Click(); singlBbuyElement.First().Click(); } selenium.SwitchTo().DefaultContent(); } catch (Exception ex) { errMsg = "自动购买失败:" + ex.Message; logger.Error(errMsg); } } Match match1 = rex.Match(selenium.PageSource); string key = match1.Groups["key1"].Value; if (string.IsNullOrEmpty(key) || errMsg != string.Empty) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = errMsg != string.Empty ? errMsg : "DATA解析失败"; err = dbcontext.Insert(err); continue; } string s = DecodeHelper.QQPageDecode(key.Substring(1)); var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s); if (t.picture.Count < 1) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = "访问付费章节内容时只存在一张图片"; err = dbcontext.Insert(err); continue; } List <Page> pglst = new List <Page>(); for (int i = 0; i < t.picture.Count; i++) { if (pglst.Exists(x => x.pagesource == t.picture[i].url) == false) { pglst.Add(new Page() { chapterid = cp.chapterid, modify = DateTime.Now, shortdate = shortdate, sort = i + 1, source = cp.source, pagelocal = "", pagesource = t.picture[i].url }); } else { Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = DateTime.Now; err.shortdate = shortdate; err.message = "存在重复图片"; err = dbcontext.Insert(err); } } cp.downstatus = DownChapter.处理完链接; cp.modify = dt; dbcontext.Update(cp); dbcontext.BulkInsert(pglst); ids.Remove(cp.Id); logger.Info("QQ_page vip buy sucess:id=" + cp.Id); } } catch (Exception ex) { if (ex.Message.IndexOf("Unexpected error. System.Net.WebException:") > -1) { InitChromeDriver(); } logger.Error(ex.Message); cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } } }
public void Execute(IJobExecutionContext context) { DateTime dt = DateTime.Now; string shortdate = dt.ToString("yyyy-MM-dd"); string yesterday = dt.AddDays(-1).ToString("yyyy-MM-dd"); IQuery <Page> pq = dbcontext.Query <Page>(); IQuery <Notice> nq = dbcontext.Query <Notice>(); IQuery <Chapter> cpq = dbcontext.Query <Chapter>();//x.comicid == "1_622585" List <Chapter> cplst = cpq.Where(x => x.source == Source.QQ && x.downstatus == DownChapter.完图片 && x.updatedate != shortdate).Take(200).ToList(); List <int> ids = cplst.Select(x => x.Id).ToList(); dbcontext.Update <Chapter>(a => ids.Contains(a.Id), a => new Chapter() { updatedate = shortdate, modify = dt }); List <Chapter> chapterlst = new List <Chapter>(); foreach (var cp in cplst) { try { string chapterpage = cp.chapterurl.Replace("http://ac.qq.com", ""); var imgdata = _helper.Get(null, chapterpage); Regex rex = new Regex("var DATA = '(?<key1>.*?)',"); Match match = rex.Match(imgdata); string key = match.Groups["key1"].Value; if (string.IsNullOrEmpty(key)) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = "DATA解析失败"; err = dbcontext.Insert(err); continue; } var s = DecodeHelper.QQPageDecode(key.Substring(1)); var t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s); if (t.chapter.vipStatus == 1) { List <Page> pglst = new List <Page>(); for (int i = 0; i < t.picture.Count; i++) { pglst.Add(new Page() { chapterid = cp.chapterid, modify = dt, shortdate = shortdate, sort = i + 1, source = cp.source, pagelocal = "", pagesource = t.picture[i].url }); } List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList(); if (pgdblst.Count != pglst.Count) { List <int> idlst = pgdblst.Select(x => x.Id).ToList(); dbcontext.Delete <Page>(x => idlst.Contains(x.Id)); dbcontext.BulkInsert(pglst); cp.downstatus = DownChapter.处理完链接; cp.modify = dt; dbcontext.Update(cp); Notice notice = new Notice(); notice.noticeid = cp.chapterid; notice.noticestatus = NoticeStatus.等待处理; notice.noticetype = NoticeType.章节更新; notice.source = cp.source; notice.shortdate = shortdate; notice.modify = dt; var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault(); if (nqwait == null) { dbcontext.Insert(notice); } continue; } } else { selenium.Navigate().GoToUrl(cp.chapterurl); IList <IWebElement> frames = selenium.FindElements(By.TagName("iframe")); IWebElement controlPanelFrame = null; //commentFrame ptlogin_iframe foreach (var frame in frames) { if (frame.GetAttribute("id") == "iframeAll") { controlPanelFrame = frame; break; } } if (controlPanelFrame != null) //QQ登录 { selenium.SwitchTo().Frame(controlPanelFrame); IReadOnlyCollection <IWebElement> switchtoElement = selenium.FindElements(By.Id("switcher_plogin")); if (switchtoElement != null && switchtoElement.Count > 0) { switchtoElement.First().Click(); selenium.FindElement(By.Id("u")).Clear(); selenium.FindElement(By.Id("u")).SendKeys("2806126975"); selenium.FindElement(By.Id("p")).Clear(); selenium.FindElement(By.Id("p")).SendKeys("rby123456"); selenium.FindElement(By.Id("login_button")).Click(); } selenium.SwitchTo().DefaultContent(); } frames = selenium.FindElements(By.TagName("iframe")); IWebElement checkVipFrame = null; foreach (var frame in frames) { if (frame.GetAttribute("id") == "checkVipFrame") { checkVipFrame = frame; break; } } if (checkVipFrame != null) { selenium.SwitchTo().Frame(checkVipFrame); //自动购买 IReadOnlyCollection <IWebElement> checkAutoElement = selenium.FindElements(By.Id("check_auto_next")); IReadOnlyCollection <IWebElement> singlBbuyElement = selenium.FindElements(By.ClassName("single_buy")); if (checkAutoElement != null && singlBbuyElement != null && checkAutoElement.Count > 0 && singlBbuyElement.Count > 0) { if (singlBbuyElement.First().Text.Trim().StartsWith("点券不足")) { MailMessage msg = new MailMessage(); continue; } else { checkAutoElement.First().Click(); singlBbuyElement.First().Click(); } } } Match match1 = rex.Match(selenium.PageSource); key = match1.Groups["key1"].Value; if (string.IsNullOrEmpty(key)) { cp.downstatus = DownChapter.待处理链接; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = "DATA解析失败"; err = dbcontext.Insert(err); continue; } s = DecodeHelper.QQPageDecode(key.Substring(1)); t = JsonHelper.DeserializeJsonToObject <QQ_Page_Api>(s); List <Page> pglst = new List <Page>(); for (int i = 0; i < t.picture.Count; i++) { pglst.Add(new Page() { chapterid = cp.chapterid, modify = dt, shortdate = shortdate, sort = i + 1, source = cp.source, pagelocal = "", pagesource = t.picture[i].url }); } List <Page> pgdblst = pq.Where(x => x.chapterid == cp.chapterid).ToList(); if (pgdblst.Count != pglst.Count) { List <int> idlst = pgdblst.Select(x => x.Id).ToList(); dbcontext.Delete <Page>(x => idlst.Contains(x.Id)); dbcontext.BulkInsert(pglst); cp.downstatus = DownChapter.处理完链接; cp.modify = dt; dbcontext.Update(cp); Notice notice = new Notice(); notice.noticeid = cp.chapterid; notice.noticestatus = NoticeStatus.等待处理; notice.noticetype = NoticeType.章节更新; notice.source = cp.source; notice.shortdate = shortdate; notice.modify = dt; var nqwait = nq.Where(x => x.noticeid == cp.chapterid && x.noticestatus == NoticeStatus.等待处理 && x.noticetype == NoticeType.章节更新).FirstOrDefault(); if (nqwait == null) { dbcontext.Insert(notice); } continue; } } } catch (Exception ex) { logger.Error(ex.Message); cp.updatedate = yesterday; cp.modify = dt; dbcontext.Update(cp); Err_ChapterJob err = new Err_ChapterJob(); err.bookurl = cp.chapterurl; err.source = cp.source; err.errtype = ErrChapter.解析出错; err.modify = dt; err.shortdate = shortdate; err.message = ex.Message; err = dbcontext.Insert(err); continue; } } }