python-3.x - 使用 Python 下载存档
问题描述
我需要从此链接下载档案:
然后我需要保存它并打开它。我怎样才能做到这一点?
解决方案
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.
推荐阅读
- java - 我需要在将对象放入 MySql 之前对其进行序列化吗?
- java - 如何将 SHA1 证书作为 PrivateKeyEntry 类型而不是trustedCertEntry 导入密钥库
- r - 如何在 R 数据框中制作漂亮的“自动”数字格式?
- spring - 自定义登录JSP页面 Springboot + SpringSecurity
- twitter-bootstrap - 隐藏在黑色叠加层下的 Bootstrap 模态弹出视频
- flutter - 没有为类 'String' 定义 getter 'todoText'
- graphql - 灯塔嵌套突变 FK 字段未填充
- python - 如何调用一个简单的函数并同时运行以下行?
- angular - ASP .Net Core 3.1 Angular 模板不起作用
- drupal-8 - 视图将字段暴露过滤器与多个分类术语结合在一起 Drupal 8