Использование PuppeteerSharp с .net core api - PullRequest
0 голосов
/ 20 мая 2019

Я следую примеру «PupppeterSharpAspNetFrameworkSample» (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()"}}
...