headlessChrome

授权协议 MIT License
开发语言 JavaScript
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 澹台岳
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

DO NOT USE! This project does not work anymore due to changes in Chrome. Use the Chrome DevTools protocol in chromedp instead!

headlessChrome ��

Support only for Ubuntu on Docker for now. Mac appears to not be working. ��

A go package for working with headless Chrome. Run interactive JavaScript commands on pages with go and Chrome without a GUI. Includes a few helpful functions out of the box to query and click selector paths by their classes, divs, or html content.

You could use this package to click buttons and scrape content on/from a website as if you were a browser, or to render pages that wouldn't be supported by other things like phantomjs or casperjs. Especially useful for sites that use EmberJS, where the content is rendered by javascript after the HTML payload is delivered.

Examples

An example project that does some simple things with a Makefile and Dockerfile is in the examples directory.

Install

go get github.com/integrii/headlessChrome

Documentation

http://godoc.org/github.com/integrii/headlessChrome

Docker Version

To run Chrome headless with docker, check out examples/docker/main.go as well as examples/docker/Makefile. When in that directory, you can do make test to build and run the container with the example app inside. You will see the source of httpbin.org displayed at the end of the build and run.

Custom Flags

By default, we startup with the bare minimum flags necessary to start headless chrome and open a javascript console. If you want more flags, like a resolution size, or a custom User-Agent, you can specify it by replacing the Args variable. Just be sure to append to it so you don't kill the default flags...

headlessChrome.Args = append(headlessChrome.Args,"--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
headlessChrome.Args = append(headlessChrome.Args,"--window-size=1024,768")
Changing the Path to Chrome

Change the path to Chrome by simply setting the headlessChrome.ChromePath variable.

headlessChrome.ChromePath = `/opt/google/chrome-unstable/chrome`
JavaScript Helper Examples

Find the full list in the docs.

// click some span element from the page by its text content
browser.ClickItemWithInnerHTML("span", "Google Search",0)

// select the content of something by its css classes
browser.GetContentOfItemWithClasses("button arrow bold",0)
time.Sleep(time.Second) // give it a second to query

// read the selected stuff from the console by picking
// the next item from the output channel
fmt.Println(<-browser.Output)

Contributing

Please send pull requests! It would be good to have support for more operating systems or more handy helpers to run more commonly used javascript code easily. Adding support for other operating systems should be as simple as checking the platform type and changing the ChromePath variable's default value.

  •         最近在研究如何可以使用cmd操控Chrome,突然发现这个无头浏览器可以使用CLI Modes进行操控,这让我突然回想起来之前项目上的一个事情,也是和最近的两会有关。         在2020年夏季的时候我还在上海,因为这时候全国需要开一次很重要的会议(具体什么名字不知道了)。当时和某地动乱等因素的影响,公司某部门要在重保期间出台了一个临时管理办法,在重保期间如果发现集团网站被某

  • Headless Chrome 什么是 Headless Chrome? 在 Chrome59 中开始搭载 Headless Chrome。这是一种在无需显示 headless 的环境下运行 Chrome 浏览器的方式。从本质上来说,就是不用 Chrome 浏览器来运行 Chrome 的功能!它将 Chromium 和 Blink 渲染引擎提供的所有现代 Web 平台的功能都带入了命令行。 int

  • 前言 公司的爬虫项目使用了selenium+phantomjs,这个做过爬虫的应该都用过,但是缺点也很明显,慢,占用资源等,本身还有很多小坑就不一一列举了 后来无意中发现了headless, 参考这篇文章:https://intoli.com/blog/making-chrome-headless-undetectable/ 经过安装测试,效果确实比phantomjs好很多,目前已有的资料都是使用

  •       python爬虫写起来非常快,虽然也可以用java,但是没有python来的简洁迅速       selenium在前面总结过,是一个自动化测试库。headless chrome是无界面的浏览器模式,和PHANTOMJS类似。但是PHANTOMJS往往会出现莫名的错误,而且速度没有headless chrome快 from selenium.webdriver.chrome.optio

  • Headless Chrome and regular Chrome have the same capabilities, and running them with Selenium is a very similar process. The difference is that Headless Chrome does not generate any sort of user inter

  • #!/usr/bin/python from selenium import webdriver from selenium.webdriver.chrome.options import Options import time url = "https://www.sina.com.cn" chrome_options = Options() chrome_options.add_argume

  • 原因:linux服务器不支持中文字体 解决办法:将windows上的中文字体库复制到linux上 或者把macos上的字体拷贝到linux上。   windows操作:(这部分是在第一篇参考文档上找的) 1.在win10中,将C:\Windows\Fonts上的字体文件(ttc/ttf)复制并打包成压缩文件fonts.zip,可选择自己需要的字体 2.将fonts.zip上传到linux服务器/u

  • 如何使用Headless Chrome Headless模式是Chrome 59中的新特征。 要使用Chrome需要安装chromedriver。 from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_option

  • 使用 Headless Chrome 进行页面渲染 - 知乎专栏 使用 Headless Chrome 进行页面渲染 - 知乎专栏 posted on 2017-06-27 16:13  lexus 阅读( ...) 评论( ...) 编辑 收藏 转载于:https://www.cnblogs.com/lexus/p/7085775.html

相关阅读

相关文章

相关问答

相关文档