我正在关注示例“PuppppeterSharpAspNetFrameworkSample”(4.7.2)。但是我无法让它工作。是否可以提供一些代码或链接来说明这个词在 .net core api 2.2 中的工作方式?
public class BrowserClient
{
private static readonly string HostPath = HostingEnvironment.MapPath("~/App_Data/");
public static async Task<string> GetTextAsync(string url)
{
var browserFetcher = new BrowserFetcher(new BrowserFetcherOptions()
{
Path = HostPath
});
await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision).ConfigureAwait(false);
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions()
{
Headless = true,
ExecutablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision)
}).ConfigureAwait(false))
using(var page = await browser.NewPageAsync().ConfigureAwait(false))
{
var response = await page.GoToAsync(url).ConfigureAwait(false);
return await response.TextAsync().ConfigureAwait(false);
}
}
}
}
它抛出的错误是
{"Message":"An error has occurred.","ExceptionMessage":"Failed to create connection","ExceptionType":"PuppeteerSharp.ChromiumProcessException","StackTrace":" at PuppeteerSharp.Launcher.<LaunchAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at PuppeteerSharp.Launcher.<LaunchAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n at PupppeterSharpAspNetFrameworkSample.Services.BrowserClient.<GetTextAsync>d__1.MoveNext() in D:\\development\\screenscraping\\puppeteer-sharp\\samples\\PupppeterSharpAspNetFrameworkSample\\PupppeterSharpAspNetFrameworkSample\\Services\\BrowserClient.cs:line 20\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Protocol error(Target.setDiscoverTargets): Target closed. (An internal WebSocket error occurred. Please see the innerException, if present, for more details. )","ExceptionType":"PuppeteerSharp.TargetClosedException","StackTrace":" at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n at PuppeteerSharp.Connection.<SendAsync>d__34.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n at PuppeteerSharp.Browser.<CreateAsync>d__73.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n at PuppeteerSharp.Launcher.<LaunchAsync>d__7.MoveNext()"}}