前端就有了对 headless 浏览器的需求,最多的应用场景有两个

* UI 自动化测试:摆脱手工浏览点击页面确认功能模式
* 爬虫:解决页面内容异步加载等问题
也就有了很多杰出的实现,前端经常使用的莫过于 PhantomJS <http://phantomjs.org/> 和 selenium-webdriver
<http://seleniumhq.github.io/selenium/docs/api/javascript/>
,但两个库有一个共性——难用!环境安装复杂,API 调用不友好,1027 年 Chrome 团队连续放了两个大招Headless Chrome
<https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md> 和对应的
NodeJS APIPuppeteer <https://github.com/GoogleChrome/puppeteer>,直接让 PhantomJS 和
Selenium IDE for Firefox 作者宣布没必要继续维护其产品.

Puppeteer

如同其 github <https://github.com/GoogleChrome/puppeteer> 项目介绍:Puppeteer 是一个通过
DevTools Protocol <https://chromedevtools.github.io/devtools-protocol/> 控制
headless chrome 的 high-level Node 库,也可以通过设置使用 非 headless Chrome

我们手工可以在浏览器上做的事情 Puppeteer 都能胜任

* 生成网页截图或者 PDF
* 爬取大量异步渲染内容的网页,基本就是人肉爬虫
* 模拟键盘输入、表单自动提交、UI 自动化测试
PuppeteerSharp

Puppeteer Sharp是官方Node.JS Puppeteer API
<https://github.com/GoogleChrome/puppeteer>的.NET 移植

* 由于Puppeteer-Sharp是NetStandard 2.0库,因此最低平台版本是.NET Framework 4.6.1和.NET Core
2.0
* 支持WebSocket库的最低Windows版本是Windows 8和Windows Server 2012,具体参见
https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets?redirectedfrom=MSDN&view=netframework-4.6.1

<https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets?redirectedfrom=MSDN&view=netframework-4.6.1>
这个项目很活跃,大家可以通过作者博客上获取更新记录 http://www.hardkoded.com/ <http://www.hardkoded.com/>

博客园里有一篇文章 PuppeteerSharp+AngleSharp的爬虫实战之汽车之家数据抓取
<https://www.cnblogs.com/VAllen/p/PuppeteerSharp-AngleSharp-CrawlerSamples.html>
:https://www.cnblogs.com/VAllen/p/PuppeteerSharp-AngleSharp-CrawlerSamples.html
<https://www.cnblogs.com/VAllen/p/PuppeteerSharp-AngleSharp-CrawlerSamples.html>
更详细的介绍了如何使用PuppeterSharp。在github上还有一个PuppeterSharp的扩展项目:
https://github.com/hlaueriksson/puppeteer-sharp-contrib
<https://github.com/hlaueriksson/puppeteer-sharp-contrib> 

相关文章:

*
puppeteer,新款headless chrome!https://www.cnblogs.com/dh-dh/p/8490047.html
<https://www.cnblogs.com/dh-dh/p/8490047.html>

*
Puppeteer 应用容器化
https://www.cnblogs.com/weihanli/p/dockerize-puppeteer-apps.html
<https://www.cnblogs.com/weihanli/p/dockerize-puppeteer-apps.html> 

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信