(随记)python + selenium + Chrome 在Mac和win系统上实现

Mac验证失败,具体原因还未找到。

步骤一,先下载必要的驱动器:

下载最新版本的Chromedriver:

https://googlechromelabs.github.io/chrome-for-testing/

及版本选择:https://sites.google.com/chromium.org/driver/downloads/version-selection

其他的下载途径:

1、谷歌浏览器驱动获取地址:http://chromedriver.storage.googleapis.com/index.html

2、火狐浏览器驱动获取地址:https://github.com/mozilla/geckodriver/releases

3、Edge浏览器驱动获取地址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

下载完成后,放到根目录下:

Mac 环境配置

# 1、将ChromeDriver解压后
# 2、将ChromeDriver 拷贝一份至 

sudo CP -R /Application/path  /usr/local/bin

# 其中/Application/path ,ChromeDriver的解压路径

3、复制完成后,在terminal中进行环境配置

vim ~/.bash_profile

export PATH="$PATH:/usr/local/bin/chromedriver"

4、保存后,再运行
source ~/.bash_profile

Win环境配置

解压后,直接放至项目的根目录下记即可

步骤二,基于conda 虚拟环境,运行jupyter notebook

步骤三,安装selenium

!pip install selenium

在win上试行程序

from selenium import webdriver
driver =webdriver.Chrome()
url = "https://www.baidu.com"
driver.get(url)
driver.close()

猜你喜欢

转载自blog.csdn.net/qq_23938507/article/details/132939295