A way to program through Python to download CSV in this website using the current date?

Viewed 26

Would like to know if there is a way to download from this website https://pselookup.vrymel.com/ in the end of day report part? I have tried downloading it using requests by inputting the date but the file I'm getting is different from the actual file on click.

url = 'https://pselookup.vrymel.com/'
r = requests.get(url, allow_redirects=True)
dateToday = datetime.today().strftime('%Y-%m-%d')
csvFile = dateToday + ".csv"
open(csvFile, 'wb').write(r.content)
1 Answers

There are multiple things wrong with your code:

  • currently the only thing that you are downloading is the page under https://pselookup.vrymel.com/ itself. You need to post something to this site in order to get the response you want. I suggest you read the documentation for the requests package

  • you are using the date of the current day but as far as I can see, the site only puts out reports for finished days, meaning at some point of the day (after pselookup put out the report for the current day), your date is correct. But before the new report has been put out, you want your code to correct your date for -1 day. An example: today is the 24th and your code is asking for the report from the 24th. BUT the report from this day has not yet been put out, instead you want to ask for the report from the 23rd. Does that make sense?

  • generally, using the open() method is considered unsafe and it is recommended to use

with open() as <filename of your choosing>:

so you might want to use

with open(csvFile, "wb") as file:
    file.write(r.content)
Related