码迷,mamicode.com
首页 > 编程语言 > 详细

centos7.4 64位安装 google-chrome 与 chromedriver 运行 Python selenium 项目

时间:2018-10-06 22:07:03      阅读:533      评论:0      收藏:0      [点我收藏+]

标签:path   use   3.2   fail   trap   read   cal   serve   3.1   

 centos7.4 实例

技术分享图片

 

利用 yum 命令安装 google-chrome 超级简单(安装最新版):

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

 

chromedriver 也下载最新版就好,和Mac 版本一样,我依旧选择这个最新版本:

http://chromedriver.storage.googleapis.com/index.html?path=70.0.3538.16/

技术分享图片

Python3.7 之前安装过:

 

然后配置一下,就能跑起来 selenium 项目了,当然该 pip install xxx 安装模块就缺什么安装什么了

# 设置 webdriver 参数
        options = webdriver.ChromeOptions()
        # 设置谷歌浏览器的一些选项
        #  proxy 代理 options 选项
        options.add_argument(r--proxy--server=http:\\ + ip)
        uas = get_uas()
        # 设置user-agent
        options.add_argument(user-agent= + choice(uas))
        # 以 headless 方案运行
        options.add_argument(--headless)
        options.add_argument(--no-sandbox)
        # options.add_argument(‘--disable-dev-shm-usage‘)
        # 禁用图片访问
        # prefs = {"profile.managed_default_content_settings.images": 2}
        # options.add_experimental_option("prefs", prefs)

 如果不配置  # 以 headless 方案运行

会抛出下面异常

技术分享图片

[root@iZwz9117d4ssv2v5oe81m3Z selenium_baidu]# python testRun.py
package_util 初始化
testRun.py:32: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(path, chrome_options=options)
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/python/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/python/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "testRun.py", line 32, in get_url
    driver = webdriver.Chrome(path, chrome_options=options)
  File "/usr/python/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/python/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/python/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/python/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/python/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (unknown error: DevToolsActivePort file doesnt exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=70.0.3538.16 (16ed95b41bb05e565b11fb66ac33c660b721f778),platform=Linux 3.10.0-693.2.2.el7.x86_64 x86_64)
 

 

selenium 代码正确运行:

技术分享图片

 


 

centos7.4 64位安装 google-chrome 与 chromedriver 运行 Python selenium 项目

标签:path   use   3.2   fail   trap   read   cal   serve   3.1   

原文地址:https://www.cnblogs.com/liugx/p/9748603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!