首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python Selenium -打开带有默认用户配置文件的边缘

Python Selenium -打开带有默认用户配置文件的边缘
EN

Stack Overflow用户
提问于 2022-01-14 10:25:27
回答 2查看 991关注 0票数 0

我使用这段代码打开边缘,设置为defaut配置文件:

代码语言:javascript
运行
复制
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已经崩溃)。

EN

Stack Overflow用户

发布于 2022-01-15 23:31:32

看来你们关系很好。您需要将Default子目录从user-data-dir中提到的路径中移除。

实际上,您的代码行将是:

代码语言:javascript
运行
复制
edge_options.add_argument("user-data-dir=C:\\Users\\PopA2\\AppData\\Local\\Microsoft\\Edge\\User Data")
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70709117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档