我使用这段代码打开边缘,设置为defaut配置文件:
from msedge.selenium_tools import Edge, EdgeOptions
edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.add_argument("user-data-dir=C:\\Users\\PopA2\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default")
edge_options.add_argument("profile-directory=Profile 1")
edge_options.binary_location = r"C:\\Users\\PopA2\\Downloads\\edgedriver_win64 (1)\\msedgedriver.exe"
driver = Edge(options = edge_options, executable_path = "C:\\Users\\PopA2\\Downloads\\edgedriver_win64 (1)\\msedgedriver.exe")
driver.get('https://google.com')
driver.quit()
但是我发现了一个错误:
PS C:\Users\PopA2> & "C:/Program /Python37 37/python.exe“”c:/Users/PopA2 2/OneDrive/Desktop/test de pe net.py“回溯(最近一次调用):文件”c:/Users/PopA2 2/OneDrive Group/Desktop/test de pe net.py",第13行,在驱动程序=边缘(选项= edge_options,Files\Python37\lib\site-packages\msedge\selenium_tools\webdriver.py",executable_path = "C:\Users\PopA2\Downloads\edgedriver_win64 (1)\msedgedriver.exe")文件"C:\Program desired_capabilities=desired_capabilities中的init desired_capabilities=desired_capabilities(init desired_capabilities=desired_capabilities)文件"C:\Program第157行,init self.start_session(功能,文件“C:\ Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py",Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py",第252行,在start_session response = self.execute(Command.NEW_SESSION,parameters) File "C:\Program第321行中,在执行self.error_handler.check_response(响应)文件中”C:\Program-Files\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py“,第242行,在selenium.common.exceptions.WebDriverException:消息引发exception_class(消息、屏幕、堆栈跟踪)中:未知错误: MSEdge启动失败:已被杀死。(未知错误: DevToolsActivePort文件不存在)(从msedge位置启动的进程C:\Users\PopA2\Downloads\edgedriver_win64 (1)\msedgedriver.exe不再运行,因此MSEdgeDriver假设MSEdge已经崩溃)。
发布于 2022-01-15 23:31:32
看来你们关系很好。您需要将Default
子目录从user-data-dir
中提到的路径中移除。
实际上,您的代码行将是:
edge_options.add_argument("user-data-dir=C:\\Users\\PopA2\\AppData\\Local\\Microsoft\\Edge\\User Data")
https://stackoverflow.com/questions/70709117
复制相似问题