CentOS 7使用PuppeteerSharp无头浏览器注意事项
环境:
CentOS 7.6.1810
.net core 3.1
PuppeteerSharp 2.0.0
1.如网络部稳定可以提前下载需要的chromium
下载地址:https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/706915/chrome-linux.zip
各个系统下载地址可以查看PuppeteerSharp源码中设置的,或者用国内镜像
将压缩包解压到当前程序目录下,文件夹路径:.local-chromium/Linux-706915/chrome-linux/

如运行报错:加载libX11.so.6库错误,则先装该库
Unhandled exception. System.AggregateException: One or more errors occurred. (Failed to launch Chromium! /PuppeteerTest/PuppeteerTest/.local-chromium/Linux-/chrome-linux/chrome: error while loading shared libraries: libX11.so.: cannot open shared object file: No such file or directory
)
---> PuppeteerSharp.ChromiumProcessException: Failed to launch Chromium! /PuppeteerTest/PuppeteerTest/.local-chromium/Linux-/chrome-linux/chrome: error while loading shared libraries: libX11.so.: cannot open shared object file: No such file or directory at PuppeteerSharp.ChromiumProcess.State.StartingState.StartCoreAsync(ChromiumProcess p)
at PuppeteerSharp.ChromiumProcess.State.StartingState.StartCoreAsync(ChromiumProcess p)
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
--- End of inner exception stack trace ---
从pkgs网站找到该库 https://pkgs.org/download/libX11.so.6

进入该库
https://centos.pkgs.org/7/centos-x86_64/libX11-1.6.7-2.el7.i686.rpm.html
找到yum安装命令:
Install libX11 rpm package: # yum install libX11

在Xshell执行该命令


其他库报错,如libXcomposite库,则一样到pkgs网站查找库和安装命令
Unhandled exception. System.AggregateException: One or more errors occurred. (Failed to launch Chromium! /PuppeteerTest/PuppeteerTest/bin/Debug/netcoreapp3./.local-chromium/Linux-/chrome-linux/chrome: error while loading shared libraries: libXcomposite.so.: cannot open shared object file: No such file or directory
)
---> PuppeteerSharp.ChromiumProcessException: Failed to launch Chromium! /PuppeteerTest/PuppeteerTest/bin/Debug/netcoreapp3./.local-chromium/Linux-/chrome-linux/chrome: error while loading shared libraries: libXcomposite.so.: cannot open shared object file: No such file or directory at PuppeteerSharp.ChromiumProcess.State.StartingState.StartCoreAsync(ChromiumProcess p)
at PuppeteerSharp.ChromiumProcess.State.StartingState.StartCoreAsync(ChromiumProcess p)
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
--- End of inner exception stack trace ---

其他库报错安装方法一样。
报libXss.so.1这个库错误的时候,运行命令:
yum install libXss* -y
报libatk-1.0.so库错误运行命令:
yum install atk
报libatk-bridge-2.0.so库错误运行命令:
yum install at-spi2-atk-devel
报libpangocairo-1.0.so库错误运行命令:
yum install pango-devel
报libgtk-3.so库错误运行命令:
yum install gtk3-devel
Pupperteer官网可以查到CentOS的相关依赖
https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

全部依赖都安装好后,运行还是报错:--no-sandbox
Unhandled exception. System.AggregateException: One or more errors occurred. (Failed to launch Chromium! [/165456.543755:ERROR:zygote_host_impl_linux.cc()] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
)
---> PuppeteerSharp.ChromiumProcessException: Failed to launch Chromium! [/165456.543755:ERROR:zygote_host_impl_linux.cc()] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. at PuppeteerSharp.ChromiumProcess.State.StartingState.StartCoreAsync(ChromiumProcess p)
at PuppeteerSharp.ChromiumProcess.State.StartingState.StartCoreAsync(ChromiumProcess p)
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
--- End of inner exception stack trace ---
根据网上的一篇文章,启动的时候需要加上--no-sandbox参数
https://segmentfault.com/a/1190000018553178
var launchOptions = new LaunchOptions
{
Headless = true
};
launchOptions.Args = new string[] {
"--no-sandbox"
};
var browser = Puppeteer.LaunchAsync(launchOptions).Result;
重新启动下程序,已经可以抓取网页了。
CentOS 7使用PuppeteerSharp无头浏览器注意事项的更多相关文章
- selenium+谷歌无头浏览器爬取网易新闻国内板块
网页分析 首先来看下要爬取的网站的页面 查看网页源代码:你会发现它是由js动态加载显示的 所以采用selenium+谷歌无头浏览器来爬取它 1 加载网站,并拖动到底,发现其还有个加载更多 2 模拟点击 ...
- 无头浏览器phantomJS
selenium: 有头浏览器的代表(selenium+python也可实现静默运行 引入python的一个包,包叫:虚拟屏幕pyvirtualdisplay) PhantomJS : 无头浏览器的代 ...
- 基于Python, Selenium, Phantomjs无头浏览器访问页面
引言: 在自动化测试以及爬虫领域,无头浏览器的应用场景非常广泛,本文将梳理其中的若干概念和思路,并基于代码示例其中的若干使用技巧. 1. 无头浏览器 通常大家在在打开网页的工具就是浏览器,通过界面上输 ...
- PhantomJS框架(初识无头浏览器)
博主今天看到大神聊起 headless,首先我去了解了下这个概念 无头浏览器 selenium框架是有头浏览器的代表,即可看得见的浏览器 而headless browser无头浏览器,即看不见的浏览 ...
- Python对Selenium调用浏览器进行封装包括启用无头浏览器,及对应的浏览器配置文件
""" 获取浏览器 打开本地浏览器 打开远程浏览器 关闭浏览器 打开网址 最大化 最小化 标题 url 刷新 Python对Selenium封装浏览器调用 ------b ...
- 爬虫之 图片懒加载, selenium , phantomJs, 谷歌无头浏览器
一.图片懒加载 懒加载 : JS 代码 是页面自然滚动 window.scrollTo(0,document.body.scrollHeight) (重点) bro.execute_ ...
- Selenium 启动无头浏览器,只有chrome 和 firefox的,没有IE
使用无头浏览器,可以避免掉不确定的弹出框对脚本稳定性的影响,还能在脚本执行过程中省略掉了css 加载的时间. 以下是Selenium 启动无头浏览器的方法,只有chrome 和 firefox的. p ...
- 浏览器控制之 selenium,phantomJs谷无头浏览器
目录 浏览器控制之 selenium,phantomJs谷无头浏览器 selenium phantomJs 需求是尽可能多的爬取豆瓣网中的电影信息 谷歌无头浏览器 浏览器控制之 selenium,ph ...
- 07-selenium、PhantomJS(无头浏览器)
selenium(自动化测试工具可用于在爬虫中解决js动态加载问题) 简介(本质就是模仿浏览器工作) Selenium 是什么?一句话,自动化测试工具.它支持各种浏览器,包括 Chrome,Safar ...
随机推荐
- [netty4][netty-buffer]netty之池化buffer
PooledByteBufAllocator buffer分配 buffer分配的入口: io.netty.buffer.PooledByteBufAllocator.newDirectBuffer( ...
- CSS动画实例:Loading加载动画效果(一)
一些网站或者APP在加载新东西的时候,往往会给出一个好看有趣的Loading图,大部分的Loading样式都可以使用CSS3制作出来,它不仅比直接使用gif图简单方便,还能节省加载时间和空间.下面介绍 ...
- async + await 异步
先执行A在执行B再执行.then里面的AAA() { XXXXX一堆代码 this.BBB().then(()=>{ 其他代码 })}, async BBB(){ let res = await ...
- 修改Ceph 监视器地址
原文链接:https://blog.csdn.net/lzw06061139/article/details/51953900 获取monmap转储当前Ceph集群的monmap到/tmp/monma ...
- selenium定位方法(一)
selenium定位方法-(一) 1.定位页面元素的方式(By类的方法) 1)id定位:通过页面元素的id属性值来定位一个页面元素 注意事项:如果每次刷新网页之后元素的id属性值都不同,说 ...
- muduo源码解析9-timezone类
timezone class timezone:public copyable { }: 作用: 感觉有点看不懂,detail内部实现文件类不明白跟时区有什么关系.timezone类主要是完成各个时区 ...
- N皇后问题的二进制优化详细思路
题目啊常规解法(DFS)在此就不赘述了... 直接进入正题. 众所周知,N皇后是NP完全类问题,n稍微大了点求解过程就会变得很长. 算法方面很难再有质的效率突破,但这不妨在其他细节上下下功夫. 揆诸常 ...
- 微信商户H5支付申请不通过被驳回解法,拒绝提示:网站有不实内容或不安全信息
H5支付是指商户在微信客户端外的移动端网页展示商品或服务,用户在前述页面确认使用微信支付时,商户发起本服务呼起微信客户端进行支付.主要用于触屏版的手机浏览器请求微信支付的场景.可以方便从外部浏览器唤起 ...
- 硬核干货:4W字从源码上分析JUC线程池ThreadPoolExecutor的实现原理
前提 很早之前就打算看一次JUC线程池ThreadPoolExecutor的源码实现,由于近段时间比较忙,一直没有时间整理出源码分析的文章.之前在分析扩展线程池实现可回调的Future时候曾经提到并发 ...
- 力扣Leetcode 1248. 统计「优美子数组」
统计「优美子数组」 给你一个整数数组 nums 和一个整数 k. 如果某个 连续 子数组中恰好有 k 个奇数数字,我们就认为这个子数组是「优美子数组」. 请返回这个数组中「优美子数组」的数目. 示例 ...