Beispiel #1
0
        public static void StartProcessH(string url, string cod, string originalPath)
        {
            string[]  opt    = { "headless" };
            WebDriver driver = new WebDriver(opt);

            try
            {
                driver.Url = url + cod;

                string nome = driver.WaitElement(By.XPath("//*[@id='info']/h1")).Text;

                nome = nome.NormalizeText();

                driver.WaitElement(By.XPath("//*[@id='cover']/a")).Click();

                string pathLog = Path.Combine(originalPath, nome);
                string path    = Path.Combine(originalPath, nome);

                Generic.CreateDirectory(path);

                int contador = 1;
                Generic.file = "Iniciando Download";

                while (true)
                {
                    url = driver.WaitElement(By.XPath("//*[@id='image-container']/a/img")).GetAttribute("src");

                    string newPath = path + "\\" + contador.ToString("00") + ".jpg";

                    Generic.DownloadFile(url, newPath);

                    Generic.file = "Página " + contador.ToString("00") + " baixada";

                    if (driver.ElementIsVisible(By.XPath("//*[@class='reader-pagination']/*[@class='next']"), out var botao))
                    {
                        botao.Click();
                    }
                    else
                    {
                        break;
                    }

                    contador++;
                }
                Generic.file = "Download Concluído";
                Generic.file = "Fim da Execução";
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                driver.Dispose();
            }
        }
Beispiel #2
0
        public static void StartProcessH(string url, string cod, string originalPath)
        {
            try
            {
                HtmlWeb      get  = new HtmlWeb();
                HtmlDocument page = get.Load(url + cod);

                string nome = page.DocumentNode.SelectSingleNode("//*[@id='info']/h1").InnerText;

                nome = nome.NormalizeText();
                nome = nome.ReplaceChar();

                string pathLog = Path.Combine(originalPath, nome);
                string path    = Path.Combine(originalPath, nome);

                Generic.CreateDirectory(path);

                int contador = 1;
                Generic.file = "Iniciando Download";

                while (true)
                {
                    page = get.Load(url + cod + "/" + contador);
                    string nUrl = string.Empty;

                    try
                    {
                        nUrl = page.DocumentNode.SelectSingleNode("//*[@id='image-container']/a/img").Attributes["src"].Value;
                    }
                    catch
                    {
                        break;
                    }

                    string newPath = path + "\\" + contador.ToString("00") + ".jpg";

                    Generic.DownloadFile(nUrl, newPath);

                    Generic.file = "Página " + contador.ToString("00") + " baixada";

                    contador++;
                }
                Generic.file = "Download Concluído";
                Generic.file = "Fim da Execução";
            }
            catch (Exception e)
            {
                throw e;
            }
        }