我的脚本运行良好,但突然出现 chrome 驱动程序错误。似乎某些文件被锁定,但我无法找到。
这是我收到的错误消息:
d = webdriver.Chrome(r'C:\Users\Rahul\Downloads\chromedriver_win32\chromedriver.exe')
[0306/064432.916:ERROR:process_singleton_win.cc(420)] Lock file can not be created! Error code: 5
[0306/064432.916:ERROR:chrome_browser_main.cc(1424)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.
任何帮助将不胜感激。
这个错误信息...
[0306/064432.916:ERROR:process_singleton_win.cc(420)] Lock file can not be created! Error code: 5
[0306/064432.916:ERROR:chrome_browser_main.cc(1424)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.
...意味着可能有一些 Zombie ChromeDriver 实例锁定了当前 ChromeDriver 需要使用的配置文件。在执行过程中强行停止 Selenium 往往会留下僵尸进程和相关的进程锁。
您需要手动浏览到指定的配置文件目录并删除名为
lockfile
的文件。如果操作系统抱怨该文件正在使用中,请通过杀死所有 google-chrome 实例来关闭它们。
从硒导入网络驱动程序
从 selenium.webdriver.chrome.service 导入服务
从 selenium.webdriver.chrome.options 导入选项
导入 chromedriver_autoinstaller
导入临时文件
chrome_options = 选项()
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--无沙箱')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless') # 可选,根据您的需要
temp_user_data_dir = tempfile.mkdtemp()
chrome_options.add_argument(f"--user-data-dir={temp_user_data_dir}")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.binary_location = r"C:\Program Files\Google\Chrome\Applicatio