• linux安装selenium+chrome+phantomjs


    1. 安装 selenium

    pip3 install selenium
    pip3 安装参考

    2. 安装 ChromeDriver

    yum install chromedriver.x86_64

    3. 安装 Chrome

    1. 配置源,终端复制执行下面的代码
    cat << EOF > /etc/yum.repos.d/google-chrome.repo
    [google-chrome]
    name=google-chrome
    baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
    enabled=1
    gpgcheck=1
    gpgkey=https://dl.google.com/linux/linux_signing_key.pub
    EOF
    
    1. 安装 chrome
      yum install google-chrome-stable

    4.测试

    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get('http://www.baidu.com/')
    print( driver.title )
    driver.quit()
    

    如果遇到错误"unknown error: DevToolsActivePort file doesn't exist " 使用以下配置

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--headless')
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.get('http://www.baidu.com/')
    print( driver.title )
    driver.quit()

     phantomjs 


    1.下载地址:http://phantomjs.org/download.html

    2.文件名:phantomjs-2.1.1-linux-x86_64.tar.bz2


    # 下载好后进行解压(由于是bz2格式,要先进行bzip2解压成tar格式,再使用tar解压)
    yum -y install bzip2.x86_64
    bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2

    # 再使用tar进行解压到/usr/local/目录下边
    tar xvf phantomjs-2.1.1-linux-x86_64.tar -C /usr/local/

    # 安装依赖软件
    yum -y install wget fontconfig

    # 重命名(方便以后使用phantomjs命令)
    mv /usr/local/phantomjs-2.1.1-linux-x86_64/ /usr/local/phantomjs

    # 最后一步就是建立软连接了(在/usr/bin/目录下生产一个phantomjs的软连接,/usr/bin/是啥目录应该清楚,不清楚使用 echo $PATH查看)
    ln -s /usr/local/phantomjs/bin/phantomjs /usr/bin/
    复制代码
    到这一步就安装成功了,接下来测试一下(经过上面建立的软连接,你就可以使用了,而且是想使用命令一样的进行使用哦!):

    [root@localhost ~]# phantomjs
    phantomjs>

    phantomjs> phantom.exit();

     
  • 相关阅读:
    scrapy爬虫框架学习
    python:面向对象—— __slots__来限制实例的属性命名范围
    列表list 的常用操作
    python replace()用法
    python 字符串 空字符串 len()
    python 字符串 编码问题
    python中语句、函数、类、模块、包之间的关系
    matplotlib 绘制正玄余玄曲线
    Es6/CommonJs/AMD模块系统的差异以及用法
    BOM和DOM的区别
  • 原文地址:https://www.cnblogs.com/du-jun/p/10577545.html
Copyright © 2020-2023  润新知