-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
技能树升级——Chrome Headless模式 #10
Comments
没找到Linux版本呢? |
1 similar comment
没找到Linux版本呢? |
有Ubuntu版本,参考这里https://medium.com/@dschnr/using-headless-chrome-as-an-automated-screenshot-tool-4b07dffba79a。 |
|
可以直接通过aptitude install google-chrome 安装。 |
最近看selenium webdriver ,发现chromdriver 可以设置headless. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
也许最近已经听说Chrome59将支持
headless
模式,PhantomJS
核心开发者Vitaly表示自己将会失业了。Headless模式解决了什么问题
3年前,无头浏览器
PhantomJS
已经如火如荼出现了,紧跟着NightmareJS
也成为一名巨星。无头浏览器带来巨大便利性:页面爬虫、自动化测试、WebAutomation...为啥Chrome又插了一脚
用过PhantomJS的都知道,它的环境是运行在一个封闭的沙盒里面,在环境内外完全不可通信,包括API、变量、全局方法调用等。一个之前写的微信页面爬虫,实现内外通信的方式极其Hack,为了达到目的,不择手段,令人发指,看过的哥们都会蛋疼。
So, 很自然的,Chrome59版支持的特性,全部可以利用,简直不要太爽:
技能树启动点
为了点亮技能树,我们需要以下配置:
大致来说,有那么个过程:
启动Headless模式
有各种脚本启动方式,本次我们使用termial参数方式来打开:
在Dock中,一个黄色的东西就会被启动,但是他不会跳出来。
操控无头浏览器
依旧有各种方式,我们先安装一个工具帮助我们来对黄色浏览器做点事情:
燥起来
捕获所有请求
Pretty Simple,写一个index.js:
AND run it:
结果会展示一堆url:
捕获DOM内所有图片
这次轮到演示一下如何操控DOM:
最后会返回数组,看起来像酱紫:
chrome-remote-interface 提供一套完整的API用于利用全量Chrome特性,更多使用方法参考:https://github.com/cyrus-and/chrome-remote-interface
总结
Chrome Headless特性,不仅仅革新了原有格局,而且提高开发效率,降低使用门槛,对于经常使用爬虫、自动化测试前端童鞋来说简直是巨大福音,对于新童鞋来说也是一个新潮的玩具。
The text was updated successfully, but these errors were encountered: