在老外博客上看到的
实际上载Playwright里有安装的代码,命令行也是调用其中的而已
不过不知道为什么始终有问题,在代码前用代码执行安装就能用了原博客
下面的代码直接运行即可
Console.WriteLine("Installing browsers");
// The following line installs the default browsers. If you only need a subset of browsers,
// you can specify the list of browsers you want to install among: chromium, chrome,
// chrome-beta, msedge, msedge-beta, msedge-dev, firefox, and webkit.
// var exitCode = Microsoft.Playwright.Program.Main(new[] { "install", "webkit", "chrome" });
// If you need to install dependencies, you can add "--with-deps"
var exitCode = Microsoft.Playwright.Program.Main(new[] { "install" });
if (exitCode != 0)
{
Console.WriteLine("Failed to install browsers");
Environment.Exit(exitCode);
}
Console.WriteLine("Browsers installed");
// Using playwright to launch a browser
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false
});
await using var browserContext = await browser.NewContextAsync();
var page = await browserContext.NewPageAsync();
await page.GotoAsync("https://www.baidu.com");
Console.ReadLine();
标签:Playwright,浏览器,await,装不上,browsers,install,var,Console
From: https://www.cnblogs.com/xslx/p/17097422.html