【问题标题】:Using wget to download image from url pointing to jpg使用 wget 从指向 jpg 的 url 下载图像
【发布时间】:2022-01-23 16:15:22
【问题描述】:

我有一个指向.jpg的链接:https://images.wallpapersden.com/image/download/nature-sunset-simple-minimal-illustration_am1ramqUmZqaraWkpJRnamtlrWZpaWU.jpg

我正在尝试使用wget https://images.wallpapersden.com/image/download/nature-sunset-simple-minimal-illustration_am1ramqUmZqaraWkpJRnamtlrWZpaWU.jpg下载它

我得到:

Connecting to images.wallpapersden.com (images.wallpapersden.com)|104.26.8.233|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2021-12-22 05:24:31 ERROR 403: Forbidden.

我假设我没有正确使用wget,还是需要使用其他 cli 工具?

--更新--

我刚刚得知我可以使用curl 下载图像,例如curl url/to/image.jpg > saveas.jpg,但我仍然很好奇wget 是否可以这样做?

【问题讨论】:

  • 我得到的错误完全不同:Connecting to images.wallpapersden.com|104.26.8.233|:443... connected. OpenSSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure Unable to establish SSL connection.

标签: http command-line terminal console wget


【解决方案1】:

我刚刚了解到我可以使用curl 来下载图像,例如 curl url/to/image.jpg > saveas.jpg,但我还是很好奇有没有 无论如何要使用wget 来做到这一点?

我对@9​​87654326@ 进行了一些测试,它似乎将wget 列入了黑名单。在发出 HTTP 请求时,User-Agent 标头用于告知是什么工具发出了该请求。

wget--user-agent 允许提供 User-Agent,所以 wget 在服务器上显示为其他东西,例如冒名顶替 Firefox 47 版

wget --user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0" https://images.wallpapersden.com/image/download/nature-sunset-simple-minimal-illustration_am1ramqUmZqaraWkpJRnamtlrWZpaWU.jpg

wgetman page 给出了这种能力的以下理由

       The HTTP protocol allows the clients to identify themselves
       using a "User-Agent" header field.  This enables
       distinguishing the WWW software, usually for statistical
       purposes or for tracing of protocol violations.  Wget
       normally identifies as Wget/version, version being the
       current version number of Wget.

       However, some sites have been known to impose the policy of
       tailoring the output according to the "User-Agent"-supplied
       information.  While this is not such a bad idea in theory, it
       has been abused by servers denying information to clients
       other than (historically) Netscape or, more frequently,
       Microsoft Internet Explorer.  This option allows you to
       change the "User-Agent" line issued by Wget.  Use of this
       option is discouraged, unless you really know what you are
       doing.

       Specifying empty user agent with --user-agent="" instructs
       Wget not to send the "User-Agent" header in HTTP requests.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 2011-03-09
    • 2015-11-12
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多