[英]Failed-Path Too Long error after downloading csv file using ChromeDriver and Chrome Browser launched by Selenium through cygwin in Python
I try to download csv file from the Chrome browser launched by selenium. 我尝试从selenium启动的Chrome浏览器中下载csv文件。
But 但
Failed- Path too long error
happens while downloading csv file. CSV文件下载时发生。
path: 路径:
C:/s/d/b
I change path like below, but same error... 我像下面一样更改路径,但是同样的错误...
/cygdrive/c/s/d/a
\cygdrive\c\s\d\a
\\cygdrive\\c\\s\\d\\a
csv file CSV文件
20181213171306.csv
chromedriver's path chromedriver的路径
/cygdrive/c/Users/HOGEHOGE/chromedriver_2.45.exe
Using cygwin, executing python scripts like this below. 使用cygwin,执行下面的python脚本。
python3 C:/s/d/a.py
I set the web driver option like this below. 我在下面设置了Web驱动程序选项。
DIR_DL="C:/s/d/b"
options = Options()
options.add_experimental_option("prefs", {
"download.default_directory":DIR_DL,
})
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,chrome_options=options)
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': DIR_DL}}
command_result = driver.execute("send_command", params)
Does anyone know how to fix this? 有谁知道如何解决这一问题?
"失敗-パスが長すぎます" is Japanese. “失败-パスが长すぎます”是日语。 It means "Failed- Path too long error". 这意味着“失败-路径太长错误”。
[Environment] [环境]
Windows 10 Windows 10
CYGWIN_NT-10.0 2.11.2 CYGWIN_NT-10.0 2.11.2
Python 3.6.4 的Python 3.6.4
selenium 3.141.0 硒3.141.0
chrome driver 2.45 chrome驱动程序2.45
chrome browser 71 chrome浏览器71
Try with double slash for the path name: 尝试使用双斜杠作为路径名:
C:\\d\\s\\b C:\\ d \\ S \\ b
Try also setting the driver page downloads option on init of webdriver. 还可以尝试在webdriver的初始状态下设置驱动程序页面下载选项。
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': "/path/to/download/dir"}}
command_result = driver.execute("send_command", params)
try set download directory using add_argument
尝试使用add_argument
设置下载目录
options = Options()
options.add_argument("download.default_directory=C:/s/d/b")
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=options)
This error message... 此错误消息...
Failed-Path Too Long
...implies that the ChromeDriver failed to interact with the (recently) downloaded file. ...表示ChromeDriver无法与(最近) 下载的文件进行交互。
As per the discussion Wrong error - "Path Too Long" ... Error should be "File Already Open" this issue is observed when the WebDriver instance ie the driver tries to use the downloaded file too soon. 按照讨论错误的错误-“路径太长” ...错误应该是“文件已打开”当WebDriver实例(即驱动程序尝试过早使用下载的文件)时,会出现此问题。
Error Snapshot: 错误快照:
Induce some wait between the twp steps of: 在以下twp步骤之间引起一些等待 :
I changed the CSV Download path to cygwin's to dom's path, then I succeeded to download csv file. 我将cygwin的CSV下载路径更改为dom的路径,然后成功下载了csv文件。
CSV Download's path CSV下载的路径
/cygdrive/c/Users/CSV_DOWNLOAD_PATH
↓ ↓
C:/Users/CSV_DOWNLOAD_PATH
Many thanks for your replies. 非常感谢您的答复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.