Linux install chrome、 Firefox、 Phantomjs

Linux下載火狐瀏覽器



Linux下載谷歌

  • 下載網站: https://www.google.com/chrome/

  • 安裝:

    • Ubuntu安裝:
    • CentOS安裝:
      • 打開: sudo vi /etc/yum.repos.d/google-chrome.repo
      • 寫入
      •   [google-chrome]
          name=google-chrome
          baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
          enabled=1
          gpgcheck=1
          gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
        
      • 安裝: sudo yum -y install google-chrome-stable --nogpgcheck
  • ChromeDriver下載地址: https://sites.google.com/a/chromium.org/chromedriver/downloads

  • 解壓: unzip 文件

  • 移動到: /usr/bin

  • ERROR:

    • ERROR: … wrong permissions … 解決: sudo chmod 777 chromedriver
    • ERROR: … DevToolsActivePort file doesn’t exist …
      •   from selenium import webdriver
          from selenium.webdriver.chrome.options import Options
          chrome_options = Options()
          chrome_options.add_argument("--headless")
          # chrome_options.add_argument('--no-sandbox')
          driver = webdriver.Chrome(options=chrome_options)
          # driver = webdriver.Chrome(chrome_options=chrome_options)
          driver.set_page_load_timeout(300)
          driver.set_script_timeout(300)
          driver.get('http://www.baidu.com')
        


Ubuntu下載phantomjs

  • 更新源:sudo apt-get update

  • 下載:sudo apt-get install phantomjs

  • 查看版本: phantomjs --version

  • ERROR:

    • …Could not connect to display…Aborted…
      • 打開: sudo vi /etc/profile.d/aliases.sh
      • 添加:
        • #!/bin/bash
        • alias phantomjs=“xvfb-run phantomjs”
      • 執行: source /etc/profile && phantomjs
    • Service phantomjs unexpectedly exited. Status code was: -6
      •   from selenium import webdriver  
          from pyvirtualdisplay import Display  
          display = Display(visible=0, size=(800,600))  
          display.start()  
          driver = webdriver.PhantomJS()  
          driver.get("http://www.baidu.com")  
        
  • 注意:

    • 依賴包: sudo apt install xvfb
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章