Beispiel #1
0
        public async static Task <ObservableCollection <VM_Comic> > GetMainListAsync(string uri, string cookie)
        {
            string htmlstring = await HttpHandler.GetStringWithCookie(uri, cookie + unconfig);

            return(MainString2List(htmlstring));
        }
Beispiel #2
0
        public async static Task <ObservableCollection <VM_Comic> > ParseDeepSearch(VM_Comic vmc, string cookie, CancellationToken cts)
        {
            string url = vmc.ComicLink;
            //下載原始碼
            string htmlstring = await HttpHandler.GetStringWithCookie(url, cookie + unconfig);

            if (htmlstring == string.Empty)
            {
                return(null);
            }
            //ObservableCollection<VM_Comic> tempList = new ObservableCollection<VM_Comic>();
            VM_Comic_Collect tempList = new VM_Comic_Collect();
            HtmlDocument     doc      = new HtmlDocument();

            doc.LoadHtml(htmlstring);

            //找尋最多頁面到幾號
            int      MaxPage  = 0;
            int      MaxCount = 0;
            HtmlNode pageNode = doc.DocumentNode.SelectSingleNode(@"//div[@class='gtb']");

            try
            {
                string   pageString = pageNode.InnerText;
                string[] tempArray  = pageString.Split(new char[] { ';', '&' });
                string   MaxPages   = tempArray[2];
                int      threepoint = MaxPages.IndexOf("...");
                if (threepoint != -1)
                {
                    string temp = MaxPages.Substring(threepoint + 3, (MaxPages.Length - (threepoint + 3)));
                    MaxPage = int.Parse(temp);
                }
                else
                {
                    MaxPage = (int)(long.Parse(tempArray[2]) % 10);
                    if (MaxPage == 0)
                    {
                        MaxPage = 10;
                    }
                }

                string[] tempArray2 = tempArray[0].Split(new char[] { ' ' });
                MaxCount          = int.Parse(tempArray2[5]);
                tempList.MaxCount = MaxCount;
            }
            catch (Exception e)
            {
            }

            //找名子 <h1 id="gj">[きゃろっと] 夫の同僚に過去の学生の頃の私と現在の人妻の私が種づけされちゃうお話 その後</h1>

            string   thisName = null;
            HtmlNode nameNode = doc.DocumentNode.SelectSingleNode(@"//h1[@id='gj']");

            try
            {
                thisName = nameNode.InnerText;
                if (thisName == string.Empty)
                {
                    thisName = vmc.ComicName;
                }
            }
            catch (Exception)
            {
            }


            Task[] TaskList = new Task[5];

            for (int iii = 0; iii < TaskList.Length; iii++)
            {
                TaskList[iii] = new Task(async(number) =>
                {
                    for (int ll = (int)number; ll < MaxPage; ll += TaskList.Length)
                    {
                        int kk         = ll;
                        int jj         = (kk * 40) + 1;
                        string tempStr = await HttpHandler.GetStringWithCookie(url + string.Format("?p={0}", kk), cookie + unconfig);
                        if (tempStr == string.Empty)
                        {
                            continue;
                        }
                        HtmlDocument tempDoc = new HtmlDocument();
                        tempDoc.LoadHtml(tempStr);
                        HtmlNodeCollection evenDoc = tempDoc.DocumentNode.SelectNodes(@"//div[@class='gdtm']/div/a");
                        if (evenDoc == null)
                        {
                            continue;
                        }

                        foreach (var item in evenDoc)
                        {
                            if (cts.IsCancellationRequested)
                            {
                                // 這裡撰寫取消工作的程式碼。
                                return;
                            }
                            VM_Comic tempVM      = new VM_Comic();
                            string tempComicLink = item.GetAttributeValue("href", "");

                            if (tempComicLink != null)
                            {
                                //HtmlDocument doc3 = webClient.Load(tempM.ComicLink);
                                string tempStr2 = await HttpHandler.GetStringWithCookie(tempComicLink, cookie + unconfig); //
                                if (tempStr2 == string.Empty)
                                {
                                    continue;
                                }
                                HtmlDocument tempDoc2 = new HtmlDocument();
                                tempDoc2.LoadHtml(tempStr2);


                                tempVM.ImageLink = tempDoc2.DocumentNode.SelectSingleNode(@"//img[@id='img']").GetAttributeValue("src", "");
                                tempVM.ComicLink = tempComicLink;
                            }
                            tempVM.ComicName = thisName;

                            tempVM.ComicNumber = jj.ToString();

                            //tempVM.ComicNumber = jj++.ToString();
                            lock (tempList)
                            {
                                f_OnComicInsert(tempList, tempVM);
                            }
                            jj++;
                        }
                    }
                }, iii, cts, TaskCreationOptions.LongRunning);
                TaskList[iii].Start();
            }
            Task.WaitAll(TaskList);
            return(tempList);
        }