Downloading all zip files from url

2024/7/7 7:35:06

I need to download all the zip files from the url: https://www.ercot.com

Answer

Everything you need comes from one endpoint that you can query and then download all the zip files.

Here's how:

import os
import time
from pathlib import Path
from shutil import copyfileobjimport requestsendpoint = f"https://www.ercot.com/misapp/servlets/" \f"IceDocListJsonWS?reportTypeId=11203&_={int(time.time())}"headers = {"Accept": "application/json, text/javascript, */*; q=0.01","Accept-Encoding": "gzip, deflate, utf-8","Host": "www.ercot.com","Referer": "https://www.ercot.com/mp/data-products/data-product-details?id=NP7-802-M","User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0","X-Requested-With": "XMLHttpRequest"
}os.makedirs("zip_files", exist_ok=True)
download_url = "https://www.ercot.com/misdownload/servlets/mirDownload?doclookupId="with requests.Session() as s:auction_results = s.get(endpoint, headers=headers).json()for result in auction_results["ListDocsByRptTypeRes"]["DocumentList"]:file_name = result["Document"]["ConstructedName"]zip_url = f"{download_url}{result['Document']['ReportTypeID']}"print(f"Downloading {result['Document']['FriendlyName']}...")r = s.get(zip_url, headers=headers, stream=True)with open(Path("zip_files") / file_name, 'wb') as f:copyfileobj(r.raw, f)

Download output:

Downloading 20232nd6AnnualAuctionSeq2CRRAuctionResults...
Downloading 20231st6AnnualAuctionSeq1CRRAuctionResults...
Downloading 20251st6AnnualAuctionSeq6CRRAuctionResults...
...

This should give you a folder named zip_files that contains:

zip_files/
├── rpt.00011203.0000000000000000.20200103.100105725.20211st6AnnualAuctionSeq3CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200206.100132142.20212nd6AnnualAuctionSeq4CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200305.100126722.20221st6AnnualAuctionSeq5CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200402.100100899.20222nd6AnnualAuctionSeq6CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200430.100110058.20202nd6AnnualAuctionSeq1CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200604.100110480.20211st6AnnualAuctionSeq2CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200702.100115453.20212nd6AnnualAuctionSeq3CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200806.100118989.20221st6AnnualAuctionSeq4CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20200903.100055873.20222nd6AnnualAuctionSeq5CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20201001.100059887.20231st6AnnualAuctionSeq6CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20201105.100138522.20211st6AnnualAuctionSeq1CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20201203.100105088.20212nd6AnnualAuctionSeq2CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210105.100208000.20221st6AnnualAuctionSeq3CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210204.100109061.20222nd6AnnualAuctionSeq4CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210304.100107618.20231st6AnnualAuctionSeq5CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210401.100114752.20232nd6AnnualAuctionSeq6CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210506.100121795.20212nd6AnnualAuctionSeq1CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210603.100129464.20221st6AnnualAuctionSeq2CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210701.100127848.20222nd6AnnualAuctionSeq3CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210805.100115654.20231st6AnnualAuctionSeq4CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210902.100111410.20232nd6AnnualAuctionSeq5CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20210930.100118983.20241st6AnnualAuctionSeq6CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20211104.100126210.20221st6AnnualAuctionSeq1CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20211202.100129217.20222nd6AnnualAuctionSeq2CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220104.100123693.20231st6AnnualAuctionSeq3CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220203.100118822.20232nd6AnnualAuctionSeq4CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220303.100110243.20241st6AnnualAuctionSeq5CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220331.100104447.20242nd6AnnualAuctionSeq6CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220505.100109570.20222nd6AnnualAuctionSeq1CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220602.100104646.20231st6AnnualAuctionSeq2CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220630.100107920.20232nd6AnnualAuctionSeq3CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220804.100105512.20241st6AnnualAuctionSeq4CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20220901.100103704.20242nd6AnnualAuctionSeq5CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20221006.100123996.20251st6AnnualAuctionSeq6CRRAuctionResults.zip
├── rpt.00011203.0000000000000000.20221103.100114498.20231st6AnnualAuctionSeq1CRRAuctionResults.zip
└── rpt.00011203.0000000000000000.20221201.130125954.20232nd6AnnualAuctionSeq2CRRAuctionResults.zip
https://en.xdnf.cn/q/120254.html

Related Q&A

sql to query set

I have 2 tables:puzz_meeting_candidats :- id, canceled, candidat_id, meeting_id puzz_meeting :- id, ClientI have a query follow: SELECT U1.`candidat_id` AS Col1 FROM `puzz_meeting_candidats` U1 INN…

Google App Engine, best practice to schedule code execution [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…

delete rows by date and add file name column for multiple csv

I have multiple "," delimited csv files with recorded water pipe pressure sensor data, already sorted by date older-newer. For all original files, the first column always contains dates forma…

X = Y = Lists vs Numbers [duplicate]

This question already has answers here:Immutable vs Mutable types(20 answers)How do I clone a list so that it doesnt change unexpectedly after assignment?(24 answers)Closed 4 years ago.In python : I h…

Python data text file grades program

Looking for help with my program. There is a text file with 5 first and last names and a number grade corresponding to each person. The task is to create a user name and change the number grade to a le…

how to fill NA with mean only for 2 or less consequective values of NA

I am new to python. please help me how I should proceed. The following dataframe contains large blocks of NaNs. # Fill the NAs with mean only for 2 or less consecutive values of NAs. # Refer to the d…

Build a new dictionary from the keys of one dictionary and the values of another dictionary

I have two dictionaries:dict_1 = ({a:1, b:2,c:3}) dict_2 = ({x:4,y:5,z:6})I want to take the keys from dict_1 and values from dict_2 and make a new dict_3dict_3 = ({a:4,b:5,c:6})

Python 2.7 - clean syntax for lvalue modification

It is very common to have struct-like types that are not expected to be modified by distant copyholders.A string is a basic example, but thats an easy case because its excusably immutable -- Python is …

Python - Global name date is not defined [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Python update user input with tkinter button

Im just starting with python and im having a problem. Ive tried various solutions, but i cant update the field that says 19. When i click on plus, i want it to be 20, then 21,... and when i click - it …