繁体   English   中英

如何使用 Python 抓取下载 zip 文件?

[英]How to download zip file using Python scraping?

我想下载这个链接的 zip 文件。 我尝试了各种方法,但我无法做到这一点。

url = "https://www.cms.gov/apps/ama/license.asp?file=http://download.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/Medicare-Provider-Charge-Data/Downloads/Medicare_National_HCPCS_Aggregate_CY2017.zip"

# downloading with requests

# import the requests library
import requests


# download the file contents in binary format
r = requests.get(url)

# open method to open a file on your system and write the contents
with open("minemaster1.zip", "wb") as code:
    code.write(r.content)


# downloading with urllib

# import the urllib library
import urllib

# Copy a network object to a local file
urllib.request.urlretrieve(url, "minemaster.zip")

任何人都可以帮助我解决这个问题。

他们正在使用一些接受/拒绝机制,因此您需要将此参数添加到 url:

url = 'http://download.cms.gov/Research-Statistics-Data-and-Systems/Statistics-Trends-and-Reports/Medicare-Provider-Charge-Data/Downloads/Medicare_National_HCPCS_Aggregate_CY2017.zip?agree=yes&next=Accept'

暂无
暂无

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

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