简体   繁体   English

Ubuntu:使用 curl 下载图像

[英]Ubuntu: Using curl to download an image

I want to download an image accessible from this link: https://www.python.org/static/apple-touch-icon-144x144-precomposed.png into my local system.我想下载可从此链接访问的图像: https://www.python.org/static/apple-touch-icon-144x144-precomposed.png : https://www.python.org/static/apple-touch-icon-144x144-precomposed.png到我的本地系统。 Now, I'm aware that the curl command can be used to download remote files through the terminal.现在,我知道curl命令可用于通过终端下载远程文件。 So, I entered the following in my terminal in order to download the image into my local system:因此,我在终端中输入以下内容,以便将图像下载到我的本地系统中:

curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

However, this doesn't seem to work, so obviously there is some other way to download images from the Internet using curl .但是,这似乎不起作用,因此显然还有其他方法可以使用curl从 Internet 下载图像。 What is the correct way to download images using this command?使用此命令下载图像的正确方法是什么?

curl without any options will perform a GET request.没有任何选项的curl将执行 GET 请求。 It will simply return the data from the URI specified.它将简单地从指定的 URI 返回数据。 Not retrieve the file itself to your local machine.不将文件本身检索到您的本地机器。

When you do,当你这样做时,

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

You will receive binary data:您将收到二进制数据:

                   |�>�$! <R�HP@T*�Pm�Z��jU֖��ZP+UAUQ@�
��{X\� K���>0c�yF[i�}4�!�V̧�H_�)nO#�;I��vg^_ ��-Hm$$N0.
���%Y[�L�U3�_^9��P�T�0'u8�l�4 ...

In order to save this, you can use:为了保存它,您可以使用:

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png > image.png

to store that raw image data inside of a file.将原始图像数据存储在文件中。

An easier way though, is just to use wget .不过,更简单的方法是使用wget

$ wget https://www.python.org/static/apple-touch-icon-144x144-precomposed.png
$ ls
.
..
apple-touch-icon-144x144-precomposed.png

For those who don't have nor want to install wget, curl -O (capital "o", not a zero) will do the same thing as wget .对于那些没有也不想安装 wget 的人, curl -O (大写“o”,不是零)将执行与wget相同的操作。 Eg my old netbook doesn't have wget, and is a 2.68 MB install that I don't need.例如,我的旧上网本没有 wget,并且是我不需要的 2.68 MB 安装。

curl -O https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

If you want to keep the original name — use uppercase -O如果要保留原始名称 - 使用大写-O

curl -O https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

If you want to save remote file with a different name — use lowercase -o如果要使用不同的名称保存远程文件 - 使用小写-o

curl -o myPic.png https://www.python.org/static/apple-touch-icon-144x144-precomposed.png

Create a new file called files.txt and paste the URLs one per line.创建一个名为 files.txt 的新文件并在每行粘贴一个 URL。 Then run the following command.然后运行以下命令。

xargs -n 1 curl -O < files.txt

source: https://www.abeautifulsite.net/downloading-a-list-of-urls-automatically来源: https : //www.abeautifulsite.net/downloading-a-list-of-urls-automatically

对于那些因保存操作而被permission denied的人,这是对我有用的命令:

$ curl https://www.python.org/static/apple-touch-icon-144x144-precomposed.png --output py.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM