Skip to content

Commit

Permalink
se reparo error al obtener las imagenes de los capitulos
Browse files Browse the repository at this point in the history
  • Loading branch information
julioolivares90 committed Apr 14, 2021
1 parent 7d4d3fa commit 1750b54
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
5 changes: 3 additions & 2 deletions ErinaScraper.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("---------------------------------------");
}
Expand Down
26 changes: 26 additions & 0 deletions ErinaScraper/src/ErinaScraper/ErinaClientHttp.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
42 changes: 28 additions & 14 deletions ErinaScraper/src/ErinaScraper/ScraperCharpetersFromManga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<string>> GetImagenesOfCharpeter(string urlRefer, string urlCapitulo)
{
var imagenes = new List<string>();

var newUrl = getUrlFromScrape(urlCapitulo);
var newUrl = await getUrlFromScrape(urlCapitulo,urlRefer);

var content = await GetBodyFromPageAsync(urlRefer, newUrl);

Expand All @@ -31,33 +33,45 @@ public async Task<List<string>> GetImagenesOfCharpeter(string urlRefer, string u
}


private string getUrlFromScrape(string urlCapitulo)
private async Task<string> 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<string> 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;
}
Expand Down

0 comments on commit 1750b54

Please sign in to comment.