コード例 #1
0
        private List <string> GetFromNinemanga()
        {
            List <string> imgURLs = new List <string>();
            HtmlWeb       web     = new HtmlWeb();
            int           iRat;

            if (int.TryParse(URL.TrimEnd('/').Split('/').Last().Split('.').FirstOrDefault().Split('-').FirstOrDefault(), out iRat))
            {
                using (CustomWebClient.WebClient client = new CustomWebClient.WebClient())
                {
                    HtmlDocument doc = new HtmlDocument();

                    doc.LoadHtml(client.DownloadStringGzip(URL));

                    Uri oURI = new Uri(URL);

                    string sNext = "";
                    Title = doc.DocumentNode.SelectSingleNode(@"//*[@id=""chapter""]").ChildNodes.FirstOrDefault(x => x.Attributes.Any(y => y.Name == "selected")).NextSibling.InnerText;
                    while (doc.DocumentNode.SelectSingleNode(@"/html/head/title").InnerText.Contains(Title))
                    {
                        foreach (HtmlNode oNode in doc.DocumentNode.Descendants("img").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("manga_pic")))
                        {
                            imgURLs.Add(oNode.Attributes.FirstOrDefault(x => x.Name == "src").Value);
                        }
                        sNext = oURI.Scheme + @"://" + oURI.Authority + doc.DocumentNode.SelectNodes("/html/body/div[3]/div[2]/div[3]/a[1]")[0].Attributes[0].Value;
                        doc.LoadHtml(client.DownloadStringGzip(sNext));
                    }
                }
            }
            else
            {
                HtmlDocument doc = web.Load(URL);
                Title = "Collection";
                foreach (HtmlNode oNode in doc.DocumentNode.SelectNodes("/html/body/div[2]/div/div[3]/div[2]")[0].ChildNodes.Where(x => x.Attributes.Any(y => y.Name == "class" && y.Value == "sub_vol_ul")))
                {
                    imgURLs.Add("http://es.ninemanga.com" + oNode.SelectSingleNode("/em/a[1]").Attributes.FirstOrDefault(x => x.Name == "href").Value);
                }
            }
            return(imgURLs);
        }
コード例 #2
0
        private void frmBrowser_Load(object sender, EventArgs e)
        {
            HtmlWeb web = new HtmlWeb();

            brsMain.ScriptErrorsSuppressed = true;
            if (RSS != null)
            {
                RSS = GetFromBrowser(RSS);
            }
            else
            {
                imgURLs = new List <string>();

                int iRat;

                if (int.TryParse(URL.TrimEnd('/').Split('/').Last().Split('.').FirstOrDefault().Split('-').FirstOrDefault(), out iRat))
                {
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    string sImgUR;
                    string sNext  = URL;
                    bool   bRetry = true;
                    doc.LoadHtml(GetFromBrowser(sNext));
                    Title = doc.DocumentNode.SelectSingleNode(@"//*[@id=""chapter""]").ChildNodes.FirstOrDefault(x => x.Attributes.Any(y => y.Name == "selected")).NextSibling.InnerText;
                    while (bRetry)
                    {
                        try
                        {
                            while (doc.DocumentNode.SelectSingleNode(@"/html/head/title").InnerText.Contains(Title))
                            {
                                foreach (HtmlNode oNode in doc.DocumentNode.Descendants("img").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("manga_pic")))
                                {
                                    sImgUR = oNode.Attributes.FirstOrDefault(x => x.Name == "src")?.Value;
                                    using (CustomWebClient.WebClient wc = new CustomWebClient.WebClient())
                                    {
                                        if (wc.DoesFileExist(sImgUR))
                                        {
                                            imgURLs.Add(sImgUR);
                                        }
                                        else
                                        {
                                            throw new Exception("404 file not found");
                                        }
                                    }
                                }
                                doc.LoadHtml(ClickonLink(NextButton));
                                if (brsMain.Document.Body.InnerHtml.ToString().Contains("all_imgs_url"))
                                {
                                    imgURLs = GetAllImagesFromJSVariable();
                                    if (imgURLs.Any())
                                    {
                                        this.Close();
                                        return;
                                    }
                                }
                            }
                            bRetry = false;
                        }
                        catch
                        {
                            try
                            {
                                if (imgURLs.Count == 0)
                                {
                                    ClickonLink(NextButton);
                                    doc.LoadHtml(ClickonLink(PrevButton));
                                }
                                else
                                {
                                    ClickonLink(PrevButton);
                                    doc.LoadHtml(ClickonLink(NextButton));
                                }
                                bRetry = true;
                            }
                            catch
                            {
                                bRetry = false;
                            }
                        }
                    }
                }
                else
                {
                    HtmlAgilityPack.HtmlDocument doc = web.Load(URL);
                    Title = "Collection";
                    foreach (HtmlNode oNode in doc.DocumentNode.SelectNodes("/html/body/div[2]/div/div[3]/div[2]")[0].ChildNodes.Where(x => x.Attributes.Any(y => y.Name == "class" && y.Value == "sub_vol_ul")))
                    {
                        imgURLs.Add("http://es.ninemanga.com" + oNode.SelectSingleNode("/em/a[1]").Attributes.FirstOrDefault(x => x.Name == "href").Value);
                    }
                }
            }
            this.Close();
        }