0


Chrome webdriver下载-避坑

WebDriver以原生的方式驱动浏览器,不需要调整环境变量。

一、window版

1.chrome和chromedriver下载地址:

Chrome for Testing availability

我下载的是如下两个安装包,解压即可。

2.导包

  1. pip install selenium

然后用python代码引用即可

二、Linux版

1.chrome和chromedriver下载地址:Chrome for Testing availability

操作步骤:

  1. #chrome
  2. unzip chrome-linux64.zip
  3. sudo mv chrome-linux64 /opt/google-chrome
  4. sudo ln -s /opt/google-chrome/chrome /usr/bin/google-chrome
  5. #通过在终端中输入 google-chrome 来运行 Chrome
  6. #chromdriver
  7. unzip chromedriver-linux64.zip
  8. sudo mv chromedriver-linux64/chromedriver /usr/local/bin/
  9. sudo chmod +x /usr/local/bin/chromedriver
  10. #使用方法
  11. from selenium import webdriver
  12. from selenium.webdriver.chrome.service import Service
  13. from selenium.webdriver.chrome.options import Options
  14. def get_webdriver():
  15. options = Options()
  16. options.add_argument("--headless") # 如果需要无头模式
  17. service = Service('/usr/local/bin/chromedriver')
  18. return webdriver.Chrome(service=service, options=options)
  19. # 使用 WebDriver
  20. driver = get_webdriver()
  21. driver.get('https://www.example.com')
  22. print(driver.title)
  23. driver.quit()

查看版本看是否匹配:

  1. chromedriver --version
  2. google-chrome --version
标签: python 开发语言

本文转载自: https://blog.csdn.net/chengzijiaotang/article/details/143799430
版权归原作者 T'iam 所有, 如有侵权,请联系我们删除。

“Chrome webdriver下载-避坑”的评论:

还没有评论