【问题标题】:How to download zip file using Python scraping?如何使用 Python 抓取下载 zip 文件?
【发布时间】:2020-02-05 11:02:55
【问题描述】:

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

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")

谁能帮我解决这个问题。

【问题讨论】:

    标签: python python-3.x web-scraping


    【解决方案1】:

    他们正在使用一些接受/拒绝机制,因此您需要将此参数添加到 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'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 2017-07-10
      • 1970-01-01
      相关资源
      最近更新 更多