环境:

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源码中设置的,或者用国内镜像

https://github.com/hardkoded/puppeteer-sharp/blob/37ea56934281209830254df3ec3ffe37c57cfac2/lib/PuppeteerSharp/BrowserFetcher.cs

将压缩包解压到当前程序目录下,文件夹路径:.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 ---

https://centos.pkgs.org/

其他库报错安装方法一样。

报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无头浏览器注意事项的更多相关文章

  1. selenium+谷歌无头浏览器爬取网易新闻国内板块

    网页分析 首先来看下要爬取的网站的页面 查看网页源代码:你会发现它是由js动态加载显示的 所以采用selenium+谷歌无头浏览器来爬取它 1 加载网站,并拖动到底,发现其还有个加载更多 2 模拟点击 ...

  2. 无头浏览器phantomJS

    selenium: 有头浏览器的代表(selenium+python也可实现静默运行 引入python的一个包,包叫:虚拟屏幕pyvirtualdisplay) PhantomJS : 无头浏览器的代 ...

  3. 基于Python, Selenium, Phantomjs无头浏览器访问页面

    引言: 在自动化测试以及爬虫领域,无头浏览器的应用场景非常广泛,本文将梳理其中的若干概念和思路,并基于代码示例其中的若干使用技巧. 1. 无头浏览器 通常大家在在打开网页的工具就是浏览器,通过界面上输 ...

  4. PhantomJS框架(初识无头浏览器)

    博主今天看到大神聊起 headless,首先我去了解了下这个概念  无头浏览器 selenium框架是有头浏览器的代表,即可看得见的浏览器 而headless browser无头浏览器,即看不见的浏览 ...

  5. Python对Selenium调用浏览器进行封装包括启用无头浏览器,及对应的浏览器配置文件

    """ 获取浏览器 打开本地浏览器 打开远程浏览器 关闭浏览器 打开网址 最大化 最小化 标题 url 刷新 Python对Selenium封装浏览器调用 ------b ...

  6. 爬虫之 图片懒加载, selenium , phantomJs, 谷歌无头浏览器

    一.图片懒加载 懒加载 :    JS 代码  是页面自然滚动    window.scrollTo(0,document.body.scrollHeight)   (重点) bro.execute_ ...

  7. Selenium 启动无头浏览器,只有chrome 和 firefox的,没有IE

    使用无头浏览器,可以避免掉不确定的弹出框对脚本稳定性的影响,还能在脚本执行过程中省略掉了css 加载的时间. 以下是Selenium 启动无头浏览器的方法,只有chrome 和 firefox的. p ...

  8. 浏览器控制之 selenium,phantomJs谷无头浏览器

    目录 浏览器控制之 selenium,phantomJs谷无头浏览器 selenium phantomJs 需求是尽可能多的爬取豆瓣网中的电影信息 谷歌无头浏览器 浏览器控制之 selenium,ph ...

  9. 07-selenium、PhantomJS(无头浏览器)

    selenium(自动化测试工具可用于在爬虫中解决js动态加载问题) 简介(本质就是模仿浏览器工作) Selenium 是什么?一句话,自动化测试工具.它支持各种浏览器,包括 Chrome,Safar ...

随机推荐

  1. go语言gRPC系列(三) - 使用grpc-gateway同时提供HTTP和gRPC服务

    1. gRPC提供HTTP服务 1.1 存在的意义 1.2 代码示例 1.3 使用postman尝试调用 1.4 gRPC客户端代码调用 2. 使用grpc-gateway同时提供HTTP和gRPC服 ...

  2. 【Hyeri】上传本地代码到Github

    个人摸索出的上传本地代码到Github的办法 首先配置SSH Key(首次需要配置) 1.设置本地ssh key,打开git bash,输入命令: ssh -keygen -t rsa -C &quo ...

  3. 封装Vue Element的form表单组件

    前两天封装了一个基于vue和Element的table表格组件,阅读的人还是很多的,看来大家都是很认同组件化.高复用这种开发模式的,毕竟开发效率高,代码优雅,逼格高嘛.虽然这两天我的心情很糟糕,就像& ...

  4. 操作系统-文件系统(3)Linux目录配置

    文件系统通常采用分层结构实现:文件管理.目录管理.磁盘管理 文件控制块(File Control Block,FCB)是操作系统为每个文件建立的唯一数据结构,包含了全部文件属性. 通常把FCB汇集.组 ...

  5. NeoVIM安装使用

    1.What's Neovim Bram Moolenaar 在写 Vim 时还是 90 年代初,至今已经 20 多年 过去了.其中,不仅包含了大量的遗留代码,而且程序的维护.Bug 的 修复.以及新 ...

  6. e3mall商城的归纳总结8之solr集群、activemq的搭建和使用

    由于本节内容比较分散,因此专门为这两个技术进行开展了帖子. solr集群的搭建 solr集群solrJ的测试 activemq的搭建 activemq的使用 引入activemq.jar包 我们先来说 ...

  7. mysql表中时间timestamp设计

    Mysql数据库中CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP区别   如图所示,mysql数据库中,当字段类型为timestamp时,如果默认值取CUR ...

  8. css面试题汇总 (持续更新)

    前言:这篇随笔是为了准备后面的面试而整理的,网上各种面试题太多了,但是我感觉很多太偏了,而且实际开发过程中并不会遇到,因此这里我整理一些比较常用的,或者是相对比较重要的知识点,每个知识点都会由浅入深, ...

  9. 【Android】SlidingTabLayout实现标题栏,教你制作title标题 简单易学。

    SlidingTabLayout 作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985, QQ986945193 微博:http://weibo.com/m ...

  10. tars 问题汇总

    1. 节点 ip地址变了如何解决.后台不可以改. 2. [ok] 服务如何在本地运行../HelloGo --config.conf