使用 Python 下载存档

Posted

技术标签:

【中文标题】使用 Python 下载存档【英文标题】:Download the archive using Python 【发布时间】:2020-07-16 17:07:05 【问题描述】:

我需要从这个链接下载存档:

http://ftp.itrc.hp.com/wpsl/bin/getFile.pl?Path=/export/patches/swa_catalog.xml.gz&Auth=05010610777284199948925117

然后我需要保存并解压它。我该怎么做?

【问题讨论】:

【参考方案1】:
import gzip
import requests

url = 'http://ftp.itrc.hp.com/wpsl/bin/getFile.pl?Path=/export/patches/swa_catalog.xml.gz&Auth=05010610777284199948925117'
xml_file = gzip.decompress(requests.get(url).content).decode('utf-8')

print(xml_file)

打印:

<?xml version="1.0" encoding="UTF-8" ?>
<!--                                                                       -->
<!-- (c)Copyright 2000-2008 Hewlett-Packard Co.,  All Rights Reserved.      -->
<!--               RESTRICTED RIGHTS LEGEND                        -->
<!-- Use, duplication, or disclosure by the U.S. Government is subject to   -->
<!-- restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in -->
<!-- Technical Data and Computer Software clause in DFARS 252.227-7013.     -->
<!--                                                                       -->
<!--                                                                       -->
<!--               Hewlett-Packard Company                         -->
<!--               3000 Hanover Street                             -->
<!--               Palo Alto, CA 94304 U.S.A.                      -->
<!--                                                                       -->
<!-- Rights for non-DOD U.S. Government Departments and Agencies are as set -->
<!-- forth in FAR 52.227-19(c)(1,2).                                        -->
<!--                                                                       -->
<!--created on 2020-07-17T14:02:31+0000 by NDist 6.2.0 (PC SIMP 2)-->
<items>
  <catalogDate value="2020-07-17T14:02:31+0000"/>
<!--from /var/opt/support/ndist/dta/current/hp-ux_patches.xml.swa.filt-->
<patch id="PHKL_21752" flags="S" cdate="2000-05-26" pdate="2000-07-28" status="GS" reboot="A" crit="N" sec="N">
<desc text="s700_800 11.04 (VVOS) Cumulative pstat fix and optimization"/>

... and so on.

【讨论】:

以上是关于使用 Python 下载存档的主要内容,如果未能解决你的问题,请参考以下文章

使用wget或curl下载网站进行存档

Java开发相关官方存档下载地址

从 GitLab 工件存档下载单个文件

打开存档而不是下载它

在 php 中创建和下载 zip 存档

Artifactory - 通用回购:存档下载失败