首页 > 其他分享 >Playwright安装问题,出现浏览器装不上时的解决方案

Playwright安装问题,出现浏览器装不上时的解决方案

时间:2023-02-07 10:14:20浏览次数:79  
标签:Playwright 浏览器 await 装不上 browsers install var Console

在老外博客上看到的
实际上载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

相关文章

  • #yyds干货盘点#理解webpack自动刷新浏览器
    在我们日常的前端开发过程中,在编辑器里只需要保存代码,浏览器就会自动刷新当前页面。这个过程被称为热更新。其实实现这一功能需要两步:监听代码的变化自动刷新浏览器下面看一......
  • Android浏览器显示大分辨率图片的问题 分享
    很多人都发现android的浏览器显示大分辨图片会出现显示模糊的问题,我测试是超过100万像素(1024x1024)的图片就会出现模糊。在android的讨论网站上也有对......
  • 按键测试,支持像 Ctrl+Alt+Shift+T 的组合键(注:非浏览器热键)
    <html><head></head><bodyonkeyup="window.alert(showKeyName(event))">按键测试,支持像Ctrl+Alt+Shift+T的组合键(注:非浏览器热键)<scripttype="text/javascript">functio......
  • playwright 运行报错ImportError: DLL load failed
    使用playwright编写了一个爬虫程序,放到远程的windowsserver服务器上面运行的时候出现下面错误File"<frozenimportlib._bootstrap>",line1206,in_gcd_importFil......
  • Chrome浏览器跨域问题处理
    1、在电脑上新建一个目录(任意位置)例如D:\chrome2、右键点击谷歌浏览器,选择属性;3、在目标输入框尾部加上  --disable-web-security--user-data-dir=D:\chrome ......
  • 67使用slenium自动化爬取200页职位信息(也可以用playwright)
    使用虚拟环境创建一个selenium版本>4因为反爬比较严重这里没用协议弄采用selenium思路:1.先用selenium,获取网页(这里获取外页,内页请求量太大),2.再解析得到我们想要的......
  • 浅谈浏览器端 WebGIS 开发可能会用到的、提升效率的 js 库
    目录前置说明1.与数据格式转换解析相关1.1.解析和转换WKT几何数据1.2.前端直接读取GeoPackage-@ngageoint/geopackage1.3.前端直接读取EsriShapefile-ts-shap......
  • 浏览器-cnblog
    事件流捕获目标冒泡回流和重绘减少回流和重绘的次数css样式一次性修改constroot=document.getElementById('root')root.style.cssText='padding:10px2......
  • http、https、浏览器介绍
    http是一个超文本传输协议,是一个客户端和服务器端请求和应答的标准(TCP),用于从web服务器传输超文本到本地浏览器的传输协议,它可以使浏览器更加高效,减少络传输。https是以安......
  • js浏览器录音功能
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-......