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
留意:Mac版需要确认selenium版本,不然会报错:
File ~/anaconda3/envs/pythonWeb/lib/python3.11/site-packages/urllib3/util/timeout.py:156, in Timeout._validate_timeout(cls, value, name)
154 float(value)
155 except (TypeError, ValueError):
--> 156 raise ValueError(
157 "Timeout value %s was %s, but it must be an "
158 "int, float or None." % (name, value)
159 ) from None
161 try:
162 if value <= 0:
ValueError: Timeout value connect was <object object at 0x10ed447a0>, but it must be an int, float or None.
此时,查看selenium版本号,输出的是:3.141.0
import selenium
print(selenium.__version__)
需要,进行版本更新:
pip install selenium==4.9.0
确认selenium版本后,需要同时确认chrome版本号及chromedrive版本是否一致。
这里通过这个地址下载了118版本:下载地址
下载后,需要运行chromedriver,找到下载后的位置,点击即可运营。
此时,在Mac上运行,即可
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()