linux系统下使用selenium驱动Chrome

写在前面:

开始使用的是xvfb + PyVirtualDisplay + firefox(60.0,centos7默认yum源的版本,ubuntu16.04安装了65.0也也试过),遇到一个比较大的坑,再模拟登录dowjones.com这个网站后,截图正常,做了一些操作,然后再截图,发现截的图只有很小一块,如下图所示

不管是调整窗口最大化还是设置尺寸,都不能解决问题,最终只能放弃,改换google-chrome-stable

换Chrome:

安装

参看Ubuntu 16.04下安装64位谷歌Chrome浏览器

踩到的坑一:

中文乱码,解决方法:

centos:

yum groupinstall fonts

 ubuntu:

sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy

踩到的坑二:

不能截图,抛time out异常

selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 10.000

解决方法:

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("start-maximized")
options.add_argument("enable-automation")
options.add_argument("--no-sandbox")
options.add_argument("--disable-infobars")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-browser-side-navigation")
options.add_argument("--disable-gpu")
driver = webdriver.Chrome(chrome_options=options)
driver.set_window_size(1024, 768)
driver.get_screenshot_as_file(STATIC_FOLDER + home_img_url)
driver.close()

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值