-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move PuppeterSharp ParseAsync method
- Loading branch information
1 parent
9554a7d
commit 5c4c8f8
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Laraue.Crawling.Dynamic.PuppeterSharp/Extensions/DocumentSchemaParserExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Laraue.Crawling.Abstractions; | ||
using PuppeteerSharp; | ||
|
||
namespace Laraue.Crawling.Dynamic.PuppeterSharp.Extensions; | ||
|
||
/// <summary> | ||
/// Transformers from opened browser page to the crawling model. | ||
/// </summary> | ||
public static class DocumentSchemaParserExtensions | ||
{ | ||
/// <summary> | ||
/// Take the opened page, use the passed schema and returns the crawling result. | ||
/// </summary> | ||
/// <param name="parser"></param> | ||
/// <param name="page"></param> | ||
/// <param name="schema"></param> | ||
/// <typeparam name="TResult"></typeparam> | ||
/// <returns></returns> | ||
/// <exception cref="InvalidOperationException"></exception> | ||
public static async Task<TResult> ParseAsync<TResult>( | ||
this IDocumentSchemaParser<IElementHandle, HtmlSelector> parser, | ||
IPage page, | ||
ICompiledDocumentSchema<IElementHandle, HtmlSelector, TResult> schema) | ||
{ | ||
var element = await page.QuerySelectorAsync("body") | ||
.ConfigureAwait(false); | ||
|
||
return await parser.RunAsync(schema, element).ConfigureAwait(false) | ||
?? throw new InvalidOperationException("Tag <body> has not been found in the passed page"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters