Skip to content

Commit

Permalink
fix studentlibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Koloskov committed Nov 3, 2023
1 parent b9f91ae commit e8ca1bb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Parsers/StudentLibrary.Parser/Logic/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private async Task<BookInfo> GetBook(HttpClient client, Uri uri) {
}

var id = uri.Segments.Last().Split(".")[0];
var detailedDescriptionBlock = doc.DocumentNode.GetByFilterFirst("div", "reader-info");
var detailedDescriptionBlock = doc.DocumentNode.GetByFilterFirst("div", "book_sticker_book");
var book = new BookInfo(id, ElsName) {
Name = doc.DocumentNode.GetByFilterFirst("h2")?.InnerText
};
Expand All @@ -54,8 +54,8 @@ private async Task<BookInfo> GetBook(HttpClient client, Uri uri) {
.Split(' ')
.First(), out book.Pages);
if(value.Contains("ISBN")) {
book.ISBN = value.Split(new []{ "ISBN" }, StringSplitOptions.None)[1].Trim()
.Split(new []{ ". " }, StringSplitOptions.None)
book.ISBN = value.Split(new []{ "ISBN"}, StringSplitOptions.None)[1].Trim()
.Split(new []{ ", " }, StringSplitOptions.None)
.First();
}
} else if (name.Contains("Издательство")) {
Expand All @@ -75,7 +75,7 @@ private static async Task<IEnumerable<Uri>> GetBookLinks(HttpClient client, Uri

return doc == default
? Enumerable.Empty<Uri>()
: doc.DocumentNode.GetByFilter("div", "wrap-title-book-sengine")
: doc.DocumentNode.GetByFilter("div", "book_sticker_sengine_librarian_right_coll")
.Select(div => div.GetByFilterFirst("a")
?.Attributes["href"]
?.Value)
Expand All @@ -84,12 +84,10 @@ private static async Task<IEnumerable<Uri>> GetBookLinks(HttpClient client, Uri

private static async Task<int> GetMaxPageCount(HttpClient client, Uri uri) {
var doc = await client.GetHtmlDoc(uri);

return doc == default
var a = doc.DocumentNode.GetByFilterFirst("a", "a_jmp_page");
return a == default
? 1
: doc.DocumentNode.GetByFilterFirst("ul", "pagination-ros-num va-m")
?.ChildNodes.Select(node => int.TryParse(node.InnerText, out var page) ? page : 1)
.Max() ?? 1;
: int.TryParse(a.InnerText, out var pages) ? pages : 1;
}

private static IEnumerable<Uri> Filter(IEnumerable<Uri> uris, ISet<string> processed) {
Expand Down

0 comments on commit e8ca1bb

Please sign in to comment.