Dockerfile
段落引用Dockerfile文件所在目录包含文件:
docker-compose.yaml
xvfb介绍
Xvfb(X Virtual Frame Buffer)是基于X Window的虚拟服务器,可以在没有物理显卡图形界面和人机交互界面的情况下,运行X Window相关应用程序.它模拟了一个完整的X Window系统,包括显示和输入设备,但一切都是在内存中进行处理,没有显示器和键盘.这使得测试和调试GUI应用程序变得更加容易和自动化.
启动X-Server命令
/usr/bin/Xvfb :99 -screen 0 1024x768x8 &
启动chrome(谷歌浏览器linux版本)
/usr/bin/google-chrome-stable --no-sandbox &
构建镜像及启动容器
docker-compose up -d
html转png
HTML内容
getWh() 用来设置png图片的宽高
截屏程序screenShotLinux
chromedp
基于Chrome DevTools协议的Go语言库:chromedp。该库提供了一种简单、高效、可靠的方式来控制Chrome浏览器进行自动化测试和爬取数据,它可以模拟用户在浏览器中执行各种操作,如点击、输入文本、截取网页长图、将网页内容转换成pdf文档、下载图片等,从而获取到需要采集的数据。项目地址: https://github.com/chromedp/chromedp