【发布时间】:2021-12-25 15:05:56
【问题描述】:
我正在尝试使用 curls 下载多个 URL:
user@PC:~$ curl -LOJ "https://example.com/foo.jpg" "https://example.com/bar.jpg"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 445 100 445 0 0 517 0 --:--:-- --:--:-- --:--:-- 518
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>404 - Not Found</title>
</head>
<body>
<h1>404 - Not Found</h1>
<script type="text/javascript" src="//wpc.75674.betacdn.net/0075674/www/ec_tpm_bcon.js"></script>
</body>
</html>
user@PC:~$ ls foo.jpg
foo.jpg
user@PC:~$ ls bar.jpg
ls: cannot access 'bar.jpg': No such file or directory
但它只将参数 (-LOJ) 应用于第一个 URL,因此只下载第一个文件。
如果我为每个 URL 重复参数,则不再出现此问题,并且两个文件都已下载:
user@PC:~$ curl -LOJ "https://example.com/foo.jpg" -LOJ "https://example.com/bar.jpg"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 445 100 445 0 0 481 0 --:--:-- --:--:-- --:--:-- 481
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 445 100 445 0 0 1534 0 --:--:-- --:--:-- --:--:-- 1539
user@PC:~$ ls foo.jpg
foo.jpg
user@PC:~$ ls bar.jpg
bar.jpg
那么有没有办法让参数应用于传递给 curl 的所有 URL,而不必为每个 URL 重复它?
【问题讨论】:
标签: bash curl http-status-code-404