Programming beginner here. So for my very first project I was able to make a quick python script that downloaded files from this website: http://www.wesm.ph/inner.php/downloads/market_prices_&_schedules
I noticed that the link address of the to-be-downloaded file
followed a pattern.
(http://wesm.ph/admin/downloads/download.php?download=../csv/mpas/XXXXX/XXXX.csv)
With some string concatenation and using the datetime module, I was able to create the HTML string of the csv file. After which, I just would use the:
urllib.request.urlopen(HTMLlink).read()
and save it with something like:
with open('output.csv', "w", newline='') as f:
writer = csv.writer(f)
writer.writerows(fullList)
It used to work - now it doesn't. I noticed however whenever I clicked the 'Generate Report' button and THEN run the script, the script would generate the output file. I'm not sure why this works. Is there a way to send a request to their server to generate the actual file? Which module, or commands should I use?
Generate reportthe website creates the file, which your script is able to download then. Probably, after a while website removes these generated reports. What you need to do is to modigy your script so that it first submits a form, then extracts url to a generated report and finally downloads it.urlliborrequests, they both have methods to make GET and POSt requests. Then you may also useBeautifulSoupto get url of the csv file. Google for it. StackOverflow is full of threads about these modules.