python 3.7
selenium 3.14.1
urllib3 1.26.8
Google Chrome 119.0.6045.160 (64位)
chromedriver.exe 119.0.6045.105(win32)
1 Google Chrome 添加参数 "--remote-debugging-port=9222"
也可以另外新建一个 .py,先运行这个 py.
import subprocess
# 配置用户数据路径
cmd = r'C:\Program Files\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222'
subprocess.run(cmd)
2 测试效果(chromedriver.exe 要和 Google Chrome 版本一致 )
最新版 chromedriver.exe 下载地址
Chrome for Testing availability
测试代码:
from selenium import webdriver
# 谷歌浏览器位置
CHROME_PATH = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
# 谷歌浏览器驱动地址
CHROMEDRIVER_PATH = r'.\chromedriver.exe'
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_options.binary_location = CHROME_PATH
driver = webdriver.Chrome(executable_path = CHROMEDRIVER_PATH, options=chrome_options)
driver.get("https://www.baidu.com/")
print(driver.title)
版权归原作者 她不喜欢喝咖啡 所有, 如有侵权,请联系我们删除。