public string GetMenu(string strURL, out string Title, out List <Comicbus_Option> listComicbus_Option) { listComicbus_Option = new List <Comicbus_Option>(); Title = ""; string strErrorMessage = ""; WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding(950); string Content = wc.DownloadString(strURL); //取得漫畫名稱 Comm_Func.GetValue(Content, out Title, "<font color=\"#FFFFFF\" style=\"font-size:10pt; letter-spacing:1px\">", "</font"); //遞迴取得所有目錄資料 strErrorMessage = ForEachGetMenu(Content, ref listComicbus_Option); return(strErrorMessage); for (int i = 0; i < listComicbus_Option.Count; i++) { Comicbus_Option comicbus_Option = listComicbus_Option[i]; if (comicbus_Option.Name.Trim() == "") { continue; } GetPageInfo(ref comicbus_Option, false, true); } //取得內頁取得總頁數 圖片 return(strErrorMessage); }
//取得所有集數 private string ForEachGetMenu(string content, ref List <Comicbus_Option> listComicbus_Option) { string strErrorMessage = ""; if (content.IndexOf("<table id=\"rp_ct") > -1) { string NewContent = ""; string Value = ""; Comm_Func.GetValue(content, out NewContent, out Value, "<table id=\"rp_ct", "</table>"); string[] TDs = Value.Split(new string[] { "<td" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < TDs.Length; i++) { string strTD = TDs[i].Trim(); if (strTD.ToUpper().IndexOf("CVIEW") > -1) { try { string Temp02 = ""; Comm_Func.GetValue(strTD, out Temp02, "onclick=\"", ";"); string Temp03 = strTD.Replace("</td>", "").Replace("</a>", "").Replace("\r\n", "").Replace("<tr>", "").Replace("</tr>", ""); Temp03 = Temp03.Substring(Temp03.LastIndexOf(">") + 1); Comicbus_Option Comicbus_Option = new Comicbus_Option(); Comicbus_Option.CVIEW = Temp02; Comicbus_Option.Name = Temp03; string Temp04 = ""; Comm_Func.GetValue(Temp02, out Temp04, "(", ")"); string[] para = Temp04.Split(new string[] { "," }, StringSplitOptions.None); //function cview(url, catid, copyright) string Temp05 = para[0].Replace("'", ""); Temp05 = Temp05.Replace(".html", "").Replace("-", ".html?ch="); string ch = Temp05.Substring(Temp05.LastIndexOf("=") + 1); //URL處理 string baseurl = "https://comicbus.live/"; if (para[2] == "1") { baseurl = "https://comicbus.live/online/c-"; } else { baseurl = "https://comicbus.live/online/a-"; } string PageURL = baseurl + Temp05; Comicbus_Option.PageURL = PageURL; Comicbus_Option.ch = ch; var v = from Comicbus_Option t in listComicbus_Option where t.Name == Comicbus_Option.Name && t.PageURL == Comicbus_Option.PageURL select t; if (v == null || v.Count() < 1) { listComicbus_Option.Add(Comicbus_Option); } } catch (Exception ex) { } } } ForEachGetMenu(NewContent, ref listComicbus_Option); } return(strErrorMessage); }
//取得總頁數跟所有圖片連結 public void GetPageInfo(ref Comicbus_Option comicbus_Option, bool GetPageURL = true, bool GetPageCount = true) { string PageURL = comicbus_Option.PageURL; string ch = "1";//傳進來的ch int Index05 = PageURL.IndexOf("ch="); int Index06 = PageURL.IndexOf("&", Index05); if (Index05 > -1) { int Length = PageURL.Length - (Index05 + 3); if (Index06 > -1 && Index06 != Index05) { Length = Index06 - (Index05 + 3); } ch = PageURL.Substring(Index05 + 3, Length); } WebClient wc = new WebClient(); wc.Encoding = Encoding.GetEncoding(950); //內頁的圖片連結 string Content2 = wc.DownloadString(PageURL); //"https://comicbus.live/online/a-18834.html?ch=1" //取得關鍵function string nviewJS = ""; #region 從nview.js取相關圖片連結之function 及 頁數的function //string nview_JS = wc.DownloadString("https://comicbus.live/js/nview.js");//取得nview.js //string[] nview_JSs = nview_JS.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); //for (int i = 0; i < nview_JSs.Length; i++) //{ // //取得連結的function // if (nview_JSs[i].IndexOf("function lc") > -1 || nview_JSs[i].IndexOf("function su") > -1 // || nview_JSs[i].IndexOf("function nn") > -1 || nview_JSs[i].IndexOf("function mm") > -1 // ) // { // nviewJS += nview_JSs[i] + "\r\n"; // } //} nviewJS = @" var y='46'; function spp(){}; var WWWWWTTTTTFFFFF=''; var document=''; function mm(p){return (parseInt((p-1)/10)%10)+(((p-1)%10)*3)}; function nn(n){return n<10?'00'+n:n<100?'0'+n:n;}; function su(a,b,c){var e=(a+'').substring(b,b+c);return (e);}; function lc(l){ if (l.length != 2) return l; var az = ""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ""; var a = l.substring(0, 1); var b = l.substring(1, 2); if (a == ""Z"") return 8000 + az.indexOf(b); else return az.indexOf(a) * 52 + az.indexOf(b); };"; #endregion Content2 = Content2.Replace("ge('TheImg').src=", "WWWWWTTTTTFFFFF="); //從內容頁取得關鍵連結資料 string[] Scripts = Content2.Split(new string[] { "<script>" }, StringSplitOptions.RemoveEmptyEntries); #region 迴圈取得關鍵連結資料 foreach (string item in Scripts) { if (item.IndexOf("function request") > -1) { string Script_Org = item.Substring(0, item.IndexOf("</script>")); //傳進來的ch Script_Org = Script_Org.Replace("var ch=request('ch');", string.Format("var ch='{0}';", ch)); nviewJS += " " + Script_Org; break; } } #endregion //取得頁數的function #region 取得頁數的function int PageCount = 0; string OnePageURL = ""; List <string> listLink = new List <string>(); if (GetPageCount && !GetPageURL)//如果要取得總頁數資料 不取連結 的話 { nviewJS += "ps;"; var PageTotal = Comm_Func.EvalJScript(nviewJS);// if (!int.TryParse(PageTotal.ToString().Trim(), out PageCount)) { PageCount = 0; } } if (!GetPageCount && GetPageURL)//如果要不取總頁數 但取得連結資料的話 { nviewJS += "\"https:\"+WWWWWTTTTTFFFFF;"; var ResultURL = Comm_Func.EvalJScript(nviewJS);// OnePageURL = ResultURL.ToString(); } if (GetPageCount && GetPageURL)//如果要取得總頁數及取得連結資料的話 { nviewJS += "ps+'__'+'https:'+WWWWWTTTTTFFFFF;"; var Result = Comm_Func.EvalJScript(nviewJS);// string[] strs = Result.ToString().Split(new string[] { "__" }, StringSplitOptions.RemoveEmptyEntries); OnePageURL = strs[1].ToString(); if (!int.TryParse(strs[0].Trim(), out PageCount)) { PageCount = 0; } for (int i = 1; i <= PageCount; i++) { string imgPath = ""; Comm_Func.GetValue(nviewJS, out imgPath, ";WWWWWTTTTTFFFFF='", ";"); imgPath = "'https:" + imgPath; string _nviewJS = nviewJS + imgPath.Replace("(p)", "(" + i + ")") + ";"; listLink.Add(Comm_Func.EvalJScript(_nviewJS).ToString().Replace(strs[0].Trim() + "__", "")); } } #endregion if (GetPageCount) { comicbus_Option.PageCount = PageCount; } if (GetPageURL) { comicbus_Option.URL = OnePageURL; if (GetPageCount) { comicbus_Option.listPic = listLink; } } #region 範例 // string RunJS2 = @" //var y=46; //function lc(l) //{ //if(l.length!=2 ) //return l; //var az='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; //var a=l.substring(0,1); //var b=l.substring(1,2); //if(a=='Z') //return 8000+az.indexOf(b); //else //return az.indexOf(a)*52+az.indexOf(b); //} //function su(a,b,c) //{ //var e=(a+'').substring(b,b+c); //return (e); //} //function nn(n) //{ //return n<10?'00'+n:n<100?'0'+n:n; // } //function mm(p){ // return (parseInt((p-1)/10)%10)+(((p-1)%10)*3) //}; //var p=1; ////最後結果 //var Result=''; ////ch是傳進來的變數 //var ch=1; //ch=parseInt(ch); //var pi=ch; //var ni=ch; //var ci=0; //var ps=0; //var chs=3; //var ti=18834; //var cs='bFdvcfBAXV6QQ74Q86BVAeS52pE8YyYPGPM99PHxuJabbebFp5tqM7R58UPdh4542T5mUCvc9bQrPMTSC7TMHspPacaMbFd396WSVPSP5xy3vWM4FtKR2hYjFwQNTEPtXHF8m2adaQ'; //for(var i=0;i<3;i++) //{ // var gtnah= lc(su(cs,i*y+0,2)); // var wcbip= lc(su(cs,i*y+2,40)); // var opufb=lc(su(cs,i*y+42,2)); // var sowlt= lc(su(cs,i*y+44,2)); // ps=sowlt; // if(opufb= ch){ // ci=i; // Result='//img'+su(gtnah, 0, 1)+'.8comic.com/'+su(gtnah,1,1)+'/'+ti+'/'+opufb+'/'+ nn(p)+'_'+su(wcbip,mm(p),3)+'.jpg'; // break; // } //} //"; #endregion }