0

i am trying to download the data from the following url and tying to save it as csv data but the output i am getting is a text file. can anyone pls help what i am doing wrong here ? also, is it possible to add multiple url in the same script and download multiple csv files.

import csv

import pandas as pd
import requests
from datetime import datetime

CSV_URL = ('https://dsv-ops-toolkit.ihsmvals.com/ftp?config=fenics-bgc&file=IRSDATA_20211129_1700_Intra.csv&directory=%2FIRS%2FIntraday%2FDaily')

with requests.Session() as s:
    download = s.get(CSV_URL)

    decoded_content = download.content.decode('utf-8')

    cr = csv.reader(decoded_content.splitlines(), delimiter=',')
    date =datetime.now().strftime('%y%m%d')
    my_list = list(cr)
    df=pd.DataFrame(my_list)
    df.to_csv(f'RFR_{date}')
Rahul Vaidya
  • 189
  • 2
  • 12

1 Answers1

0

You can create a list of your necessary URLs like:

urls = ['http://url1.com','http://url2.com','http://url3.com']

Iterate through the list for each url and your requests will be as it is:

for each_url in urls:
    with requests.Session() as s:
        # your_code_here

Hope you'll find this helpful.

Hemz
  • 29
  • 6