Introduce Beam.Fluent and Beam.Models projects
Added new Beam.Fluent and Beam.Models projects with staged download builder and data context models. Refactored and moved model classes from Beam.Temporary.Cli to Beam.Models. Added new data providers and extended DataBindings in Beam.Dynamic. Renamed Beam.Puppeteer to Beam.Playwright and updated related classes. Updated project references and package versions. Removed obsolete and unused files from Beam.Temporary.Cli.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.Playwright;
|
||||
|
||||
namespace Beam.Playwright {
|
||||
public class PlaywrightUnitPageDownloader<T> : UnitDownloader<T> {
|
||||
public PlaywrightAsyncManipulator PuppetManipulator { get; }
|
||||
|
||||
public PlaywrightUnitPageDownloader(HtmlWeb web, PlaywrightAsyncManipulator puppetManipulator, AsyncTransformer<HtmlDocument, T> asyncHtmlTransformer, AsyncDownloadFailurePredicate<HtmlDocument>[] asyncDownloadFailurePredicates)
|
||||
: base(web, asyncHtmlTransformer, asyncDownloadFailurePredicates) {
|
||||
PuppetManipulator = puppetManipulator;
|
||||
}
|
||||
|
||||
protected override async Task<(bool, T?)> TryDownloadWithNoRetries(string link, CancellationToken ct) {
|
||||
var page = await PlaywrightContext.Browser.Value.NewPageAsync();
|
||||
try {
|
||||
await page.GotoAsync(link);
|
||||
await PuppetManipulator(page);
|
||||
var content = await page.ContentAsync();
|
||||
await page.CloseAsync();
|
||||
|
||||
HtmlDocument doc = new();
|
||||
doc.LoadHtml(content);
|
||||
var transformed = await Transformer(doc);
|
||||
if (FailurePredicates is null || !(await IsFailure(doc)))
|
||||
return (true, transformed);
|
||||
return (false, default);
|
||||
} catch (Exception) {
|
||||
return (false, default);
|
||||
} finally {
|
||||
if (!page.IsClosed)
|
||||
await page.CloseAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user