diff --git a/ReadSharp.Tests/ReadTests.cs b/ReadSharp.Tests/ReadTests.cs index a38d6c5..31c1072 100644 --- a/ReadSharp.Tests/ReadTests.cs +++ b/ReadSharp.Tests/ReadTests.cs @@ -180,7 +180,10 @@ namespace ReadSharp.Tests { ReadOptions options = new ReadOptions() { MultipageDownload = true }; - Article result = await reader.Read(new Uri("http://www.anandtech.com/show/7594/samsung-ssd-840-evo-msata-120gb-250gb-500gb-1tb-review"), options); + Article result = await reader.Read(new Uri("http://www.maximumpc.com/article/features/modders_toolkit_everything_you_need_make_kick-ass_custom_case_mods"), options); + Assert.Equal(result.PageCount, 4); + + result = await reader.Read(new Uri("http://www.anandtech.com/show/7594/samsung-ssd-840-evo-msata-120gb-250gb-500gb-1tb-review"), options); Assert.Equal(result.PageCount, 9); result = await reader.Read(new Uri("http://www.zeit.de/gesellschaft/2014-02/alice-schwarzer-steuerhinterziehung-doppelmoral"), options); diff --git a/ReadSharp/Reader.cs b/ReadSharp/Reader.cs index f14e0a6..9e56506 100644 --- a/ReadSharp/Reader.cs +++ b/ReadSharp/Reader.cs @@ -39,6 +39,11 @@ namespace ReadSharp /// protected HttpOptions _options; + /// + /// The current pages + /// + protected List _currentPages = new List(); + /// /// Redirect faulty mobile URIs to desktop equivalents /// @@ -118,6 +123,8 @@ namespace ReadSharp /// public async Task
Read(Uri uri, ReadOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { + _currentPages = new List(); + Response response; string uriString = uri.OriginalString; @@ -274,6 +281,13 @@ namespace ReadSharp /// private async Task Request(Uri uri, ReadOptions options, Response previousResponse, CancellationToken cancellationToken) { + // URI already fetched + if (previousResponse != null && _currentPages.Contains(uri.OriginalString)) + { + return previousResponse; + } + _currentPages.Add(uri.OriginalString); + HttpResponseMessage response = null; TranscodingResult transcodingResult; Encoding encoding; @@ -354,7 +368,7 @@ namespace ReadSharp // in same special cases their are multiple pages, which are only comments or do not contain new content. // if this is the case we will break here and return the first page only. - if (previousResponse != null && previousResponse.TranscodingResult.ExtractedContent == transcodingResult.ExtractedContent) + if (previousResponse != null && previousResponse.TranscodingResult.ExtractedContent.Contains(transcodingResult.ExtractedContent)) { previousResponse.TranscodingResult.NextPageUrl = null; return previousResponse;