centos安装chromedriver并使用

以你之姓@ 2022-11-12 09:53 209阅读 0赞
  1. yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
  2. # 查看安装的版本
  3. chromedriver -version

根据上方查出的版本,在https://npm.taobao.org/mirrors/chromedriver中找到合适的安装包

  1. wget http://npm.taobao.org/mirrors/chromedriver/89.0.4389.23/chromedriver_linux64.zip
  2. # 解压即可使用
  3. unzip chromedriver_linux64.zip
  4. mv chromedriver /usr/local/bin/

使用selenium

  1. from selenium import webdriver
  2. driver_path = '/usr/local/bin/chromedriver'
  3. url = 'www.baidu.com'
  4. option = webdriver.ChromeOptions()
  5. option.add_argument('headless')
  6. option.add_argument('no-sandbox')
  7. option.add_argument('disable-dev-shm-usage')
  8. driver = webdriver.Chrome(driver_path, chrome_options=option)
  9. driver.get(url)
  10. content = driver.page_source
  11. driver.close()
  12. print (content)

发表评论

表情:
评论列表 (有 0 条评论,209人围观)

还没有评论,来说两句吧...

相关阅读