chrom的web driver(chromedriver.exe):
http://npm.taobao.org/mirrors/chromedriver/
firefox的web driver (geckodriver.exe):
https://github.com/mozilla/geckodriver/releases
点击进去,找到windows版。注意:windows版只有32位,没有64位
python获取自己的exe路径
新建脚本test.py
import sys
print(sys.executable)
import sys
print(sys.executable)
执行输出: E:\virtualenv\django3\Scripts\python.exe
这里,就是的python.exe路径了。
将chromedriver.exe文件放到python.exe所在的路径。
测试:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# 设置selenium使用chrome的无头模式
chrome_options = Options()
# 在启动浏览器时加入配置
browser = webdriver.Chrome(options=chrome_options)
# 打开百度
browser.get('https://www.baidu.com/')
# 等待加载,最多等待20秒
browser.implicitly_wait(20)