简体   繁体   English

使用Selenium通过cygwin在Python中使用ChromeDriver和Chrome浏览器下载csv文件后,出现路径失败的错误

[英]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: 错误快照:

路径失败太长


Solution

Induce some wait between the twp steps of: 在以下twp步骤之间引起一些等待

  • Downloading the csv file. 正在下载csv文件。
  • Using the csv file for the next action. 使用csv文件进行下一步操作。

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.

相关问题 selenium.common.exceptions.NoSuchElementException:消息:通过Selenium和Python使用ChromeDriver和Chrome没有这样的元素错误 - selenium.common.exceptions.NoSuchElementException: Message: no such element error using ChromeDriver and Chrome through Selenium and Python 无法加载资源:服务器通过 Selenium 使用 ChromeDriver Chrome 响应状态为 429(请求过多)和 404(未找到) - Failed to load resource: the server responded with a status of 429 (Too Many Requests) and 404 (Not Found) with ChromeDriver Chrome through Selenium WebDriverException:消息:未知错误:使用 ChromeDriver Chrome 通过 Selenium Python 打印 HTML 内容时出现错误检查器消息错误 - WebDriverException: Message: unknown error: bad inspector message error while printing HTML content using ChromeDriver Chrome through Selenium Python WebDriverException:消息:未知错误:Chrome 无法启动:异常退出。”(驱动程序信息:chromedriver=97)使用 Selenium Python - WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally." (Driver info: chromedriver=97) using Selenium Python 在python中使用Selenium在无头chrome中下载文件时文件未保存 - File Not Saving While Downloading File in Headless chrome using Selenium in python 无法创建着色器缓存条目:ChromeDriver Chrome 和 Selenium 出现 -2 错误 - Failed to create shader cache entry: -2 error with ChromeDriver Chrome and Selenium RuntimeError:此包仅支持 Linux、MacOSX 或 Windows 平台错误,ChromeDriver 和 Chrome 通过 Selenium 和 Python - RuntimeError: This package supports only Linux, MacOSX or Windows platforms error with ChromeDriver and Chrome through Selenium and Python 如何使用chromedriver和chrome模拟phantomjs行为以使用Selenium通过Python和contextlib获取页面上的所有链接 - How to emulate the phantomjs behavior with chromedriver and chrome to get all links on a page using Selenium through Python and contextlib 类型错误:get() 缺少 1 个必需的位置参数:通过 Selenium 和 Python 使用 ChromeDriver 和 Chrome 的“url” - TypeError: get() missing 1 required positional argument: 'url' using ChromeDriver and Chrome through Selenium and Python 如何使用 ChromeDriver 和 Selenium 通过 Python 在 Chrome 中打开和访问多个(近 50 个)标签页 - How to open and access multiple (nearly 50) tabs in Chrome using ChromeDriver and Selenium through Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM