diff --git a/ErinaScraper.Samples/Program.cs b/ErinaScraper.Samples/Program.cs index 47934e9..5131395 100644 --- a/ErinaScraper.Samples/Program.cs +++ b/ErinaScraper.Samples/Program.cs @@ -42,8 +42,9 @@ static async Task Main(string[] args) Console.WriteLine("---------------------------------------"); Console.WriteLine("---------------Manga info Capitulos -------------"); - - var mangaCapitulos = await scraper.GetCapitulosManga(urlRefer: "https://lectortmo.com/library/manga/49890/shonen-no-abyss", urlCapitulo: "https://anitoc.com/news/943785a80d0ba8316c5f894406cc406e/paginated/1"); + + //var mangaCapitulos = await scraper.GetCapitulosManga(urlRefer: "https://lectortmo.com/library/manga/49890/shonen-no-abyss", urlCapitulo: "https://anitoc.com/news/943785a80d0ba8316c5f894406cc406e/paginated/1"); + var mangaCapitulos = await scraper.GetCapitulosManga(urlRefer: "https://lectortmo.com/library/manga/30388/kanojo-okarishimasu", urlCapitulo: "https://lectortmo.com/view_uploads/250923"); mangaCapitulos.ForEach((capitulo) => Console.WriteLine(capitulo)); Console.WriteLine("---------------------------------------"); } diff --git a/ErinaScraper/src/ErinaScraper/ErinaClientHttp.cs b/ErinaScraper/src/ErinaScraper/ErinaClientHttp.cs new file mode 100644 index 0000000..34b339b --- /dev/null +++ b/ErinaScraper/src/ErinaScraper/ErinaClientHttp.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; + +namespace ErinaScraper.src.ErinaScraper +{ + class ErinaClientHttp + { + private HttpClient httpClient; + + public HttpClient InitHttp(string urlfer) + { + httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.Add("method", "GET"); + + httpClient.DefaultRequestHeaders.Add("authority", "lectortmo.com"); + + httpClient.DefaultRequestHeaders.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); + httpClient.DefaultRequestHeaders.Add("referer", urlfer); + + return httpClient; + } + + } +} diff --git a/ErinaScraper/src/ErinaScraper/ScraperCharpetersFromManga.cs b/ErinaScraper/src/ErinaScraper/ScraperCharpetersFromManga.cs index 149910c..12bc3ae 100644 --- a/ErinaScraper/src/ErinaScraper/ScraperCharpetersFromManga.cs +++ b/ErinaScraper/src/ErinaScraper/ScraperCharpetersFromManga.cs @@ -5,18 +5,20 @@ using System.Threading.Tasks; using System.Net; using AngleSharp; +using ErinaScraper.src.ErinaScraper; namespace ErinaScraper.src.ErinaScraper { public class ScraperCharpetersFromManga { - private readonly HttpClient httpClient = new HttpClient(); + + private ErinaClientHttp erinaClient = new ErinaClientHttp(); public async Task> GetImagenesOfCharpeter(string urlRefer, string urlCapitulo) { var imagenes = new List(); - var newUrl = getUrlFromScrape(urlCapitulo); + var newUrl = await getUrlFromScrape(urlCapitulo,urlRefer); var content = await GetBodyFromPageAsync(urlRefer, newUrl); @@ -31,33 +33,45 @@ public async Task> GetImagenesOfCharpeter(string urlRefer, string u } - private string getUrlFromScrape(string urlCapitulo) + private async Task getUrlFromScrape(string urlCapitulo,string urlRefer) { var newUrl = ""; - if (urlCapitulo.Contains("/paginated")) + + var client = erinaClient.InitHttp(urlRefer); + var respone = await client.GetAsync(urlCapitulo); + + if (respone.StatusCode == HttpStatusCode.OK) { - if (urlCapitulo.Contains("/paginated/1")) + + var currentUrl= respone.RequestMessage.RequestUri.ToString(); + if (currentUrl.Contains("/paginated")) { - newUrl = urlCapitulo.Replace("/paginated/1", "/cascade"); + if (currentUrl.Contains("/paginated/1")) + { + newUrl = currentUrl.Replace("/paginated/1", "/cascade"); + return newUrl; + } + newUrl = currentUrl.Replace("/paginated", "/cascade"); return newUrl; } - newUrl = urlCapitulo.Replace("/paginated", "/cascade"); - return newUrl; + return currentUrl; } - return urlCapitulo; + return newUrl; + } private async Task GetBodyFromPageAsync(string urlRefer, string urlCapitulo) { - httpClient.DefaultRequestHeaders.Add("method", "GET"); + //httpClient.DefaultRequestHeaders.Add("method", "GET"); - httpClient.DefaultRequestHeaders.Add("authority", "lectortmo.com"); + //httpClient.DefaultRequestHeaders.Add("authority", "lectortmo.com"); - httpClient.DefaultRequestHeaders.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); - httpClient.DefaultRequestHeaders.Add("referer", urlRefer); + //httpClient.DefaultRequestHeaders.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"); + //httpClient.DefaultRequestHeaders.Add("referer", urlRefer); - var response = await httpClient.GetStringAsync(urlCapitulo); + var client = erinaClient.InitHttp(urlRefer); + var response = await client.GetStringAsync(urlCapitulo); return response; }