【selenium】mac M1环境python selenium chromewebdriver环境搭建

Mac Air M1系统

  1. 按照Python3.7+的环境
  2. Pycharm安装
  3. 安装selenum 通过pip安装或者通过pycharm安装均可
  4. 安装chromewebdriver 下载地址:http://chromedriver.storage.googleapis.com/index.html,下载安装与本地chrome版本一致的webdriver,参考地址:https://cloud.tencent.com/developer/article/1365269
  5. 编写测试代码:
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2021/11/21 5:08 PM
# @Author  : baosenzhang
# @File    : Hello.py
# @Software: PyCharm

from selenium import webdriver
import time
if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.get('http://www.baidu.com')
    time.sleep(8)
    driver.close()

在Mac系统上首次运行会报错Service chromedriver unexpectedly exited. Status code was: -9,这个提示是表示Mac系统上不信任chromedriver程序,需要在Mac系统偏好–安全性与隐私–通用中点击 ‘仍要打开’,参考:https://jingyan.baidu.com/article/afd8f4de7a72b375e286e9f1.html
再次运行上面代码即可运行通过

猜你喜欢

转载自blog.csdn.net/weixin_45329445/article/details/121456826