O
O
organica2020-04-16 10:45:37
Python
organica, 2020-04-16 10:45:37

How to download a file from an indirect link?

Gentlemen, help solve the problem:
There is a site where you need to download a csv file for further data manipulation.
The link to the file is not direct, but this

CSV_URL = f'somesite.ru/?export_excel=Y&FILTER%5BUF_WAREHOUSE%5D=1&FILTER%5BUF_SHIPPING_DATE%5D%5Bstart%5D%5B0%5D={date}&FILTER%5BUF_SHIPPING_DATE%5D%5Bfinish%5D%5B0%5D={date}'

Following this link starts downloading csv with the required selection parameters.
At the moment, I'm downloading this business through Selenium, but I want to get by with a little blood through requests.
When working through Selenium, I specify download.default_directory": ROOT_PATH and the file is downloaded where necessary.

Globally, the problem is as follows: I pack this script into an .exe, but for it to work correctly, you need to carry the driver for chrome with you everywhere. It happens that on some The PC version of chrome is different and nothing works :) And if you solve this problem using requests, everything should be ok

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Pankov, 2020-04-16
@trapwalker

Open the browser debug console and see what kind of request the browser makes to download the file. Right click and copy the CURL command to run this query from the command line.
In the conditions of the meager information that you provided (without examples), nothing will tell you more.

D
Dimonchik, 2020-04-16
@dimonchik2013

normal request get
and then r.raw write binary mode

S
soremix, 2020-04-17
@SoreMix

Wouldn't that work?

r = requests.get(CSV_URL)

with open('result.csv', 'wb') as f:
    f.write(r.content)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question