我不明白...
实际的下载链接似乎不是 http 链接,而是一些 Javascript 操作?
javascript:SendFileDownloadCall('PRODIMAGES.CIF.zip','PRODIMAGES.CIF.zip');
所以手动下载后,我去浏览器的下载历史复制直接链接 https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL.TXT.zip
我将 URL 连同我的网站凭据一起输入 wget:
wget -q --user=XXXX --password=XXXX "https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL.TXT.zip" -o STDPRICE.zip
后来,我发现添加 --user 和 --password 没有区别,所以我省略了:
[root@server datafiles]# wget "https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL" -O STDPRICE.zip
--2019-09-15 19:53:29-- https://au.ingrammicro.com/_layouts/CommerceServer/IM/FileDownload.aspx?DisplayName=STD_FULL_FILEFEED.TXT&FileName=STDPRICE_FULL
Resolving au.ingrammicro.com (au.ingrammicro.com)... 104.98.45.15
Connecting to au.ingrammicro.com (au.ingrammicro.com)|104.98.45.15|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: /_layouts/CommerceServer/IM/Login.aspx?ReturnUrl=%2f_layouts%2fCommerceServer%2fIM%2fFileDownload.aspx%3fDisplayName%3dSTD_FULL_FILEFEED.TXT%26FileName%3dSTDPRICE_FULL [following]
--2019-09-15 19:53:29-- https://au.ingrammicro.com/_layouts/CommerceServer/IM/Login.aspx?ReturnUrl=%2f_layouts%2fCommerceServer%2fIM%2fFileDownload.aspx%3fDisplayName%3dSTD_FULL_FILEFEED.TXT%26FileName%3dSTDPRICE_FULL
Reusing existing connection to au.ingrammicro.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 85341 (83K) [text/html]
Saving to: ‘STDPRICE.zip’
100%[===================================================================================================================================================================================================>] 85,341 405KB/s in 0.2s
2019-09-15 19:53:30 (405 KB/s) - ‘STDPRICE.zip’ saved [85341/85341]
无论如何,我没有获得与通过人工点击并从网站下载获得的文件相同的文件,而是获得了一个小得难以置信的文件。
确认我的恐惧,当我尝试解压缩时,我得到:
$ [root@server datafiles]# unzip STDPRICE.zip
Archive: STDPRICE.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of STDPRICE.zip or
STDPRICE.zip.zip, and cannot find STDPRICE.zip.ZIP, period.
档案检查:
$ [root@server datafiles]# file STDPRICE.zip
STDPRICE.zip: HTML document, UTF-8 Unicode text, with very long lines, with CRLF line terminators
那么 wget 实际上已经下载了一个 HTML 文件,该文件被呈现为一个.txt.zip
文件?有人可以启发我吗?
该站点将您重定向到登录页面:
它可能不接受您作为基本身份验证提供的凭据(这是 wget 发送的),而是使用会话 cookie。您可以尝试从浏览器中提取 cookie(在登录时)并使用 wget (
--load-cookies
) 发送它们。他们可能还会关注您可能尝试修改的请求的其他方面(例如用户代理)。如果您可以改用 curl,请打开检查器 (
Ctrl+Shift+I
),转到网络选项卡,下载文件,右键单击请求列表中的下载条目,将鼠标悬停在“复制”上,然后选择“复制为 cURL”,现在剪贴板上的命令将包含 cookie。