【问题标题】:curl: (3) URL using bad/illegal format or missing URL in bash Windowscurl:(3)在 bash Windows 中使用错误/非法格式的 URL 或缺少 URL
【发布时间】:2022-01-11 01:25:45
【问题描述】:

我正在尝试从 .txt 文件中的 URL 列表下载 PDF 文件,每行一个 URL。 ('urls.txt')

当我使用以下命令时,我使用的 URL 是 .txt 文件第一行的精确复制粘贴:

$ curl http://www.isuresults.com/results/season1617/gpchn2016/gpchn2016_protocol.pdf -o 'test.pdf'

pdf 下载完美。但是,当我使用此命令时:

xargs -n 1 curl -O < urls.txt

然后我收到一个“卷曲:(3) URL 使用错误/非法格式或缺少 URL”错误 x 倍于 .txt 文件中列出的 URL 数量。我已经单独测试了许多 URL,它们似乎都可以正常下载。

我该如何解决这个问题?

编辑——urls.txt的前三行内容如下:

http://www.isuresults.com/results/season1718/gpf1718/gpf2017_protocol.pdf
http://www.isuresults.com/results/season1718/gpcan2017/gpcan2017_protocol.pdf
http://www.isuresults.com/results/season1718/gprus2017/gprus2017_protocol.pdf

已解决:根据下面的评论,问题在于 .txt 文件是 DOS/Windows 格式。我使用以下代码对其进行了转换:

$ dos2unix urls.txt

然后使用我的原始代码行完美下载文件。有关更多信息,请参阅此线程:Are shell scripts sensitive to encoding and line endings?

感谢所有回复的人!

【问题讨论】:

标签: bash curl


【解决方案1】:

尝试使用

xargs -n 1 -t -a urls.txt curl -O

这里的 -a 选项从文件而不是标准输入中读取列表

编辑:

正如@GordonDavisson 提到的,看起来您可能有一个带有 DOS 行结尾的文件,您可以在传递给 xargs 之前使用 sed 清理这些文件

sed 's/\r//' < urls.txt | xargs -n 1 -t curl -O

【讨论】:

猜你喜欢
  • 2019-06-03
  • 1970-01-01
  • 1970-01-01
  • 2021-12-26
  • 2022-10-14
  • 1970-01-01
  • 1970-01-01
  • 2021-12-14
  • 1970-01-01
相关资源
最近更新 更多