inspecting a HTML page i have managed to get a URL of a report i want to download
If a put the URL into a browser and press enter or put the URL into Excel and click it, a report downloads into my downloads folder
I want to be able to download the file, ideally into a variable, but right now i cant even get it to download at all
its not a public URL so i cant share that but i am able to adjust the url with the date range i want
https://blah.com/orders/download/2023-06-01/2023-06-26
im grateful for your advice
Look at a basic is in this
Post,testet now still work.
i have tried the below based on the basis of the post you have provided
i dont get an error and i dont get a download into the download folder
If it has downloaded somewhere else how can i find the path it has gone to?
url = "https://blah.com/orders/download/2023-06-01/2023-06-26"
response = requests.get(url)
with open('orders.xlsx', 'wb') as f:
f.write(response.content)
(Jun-27-2023, 05:40 PM)JayManPython Wrote: [ -> ]i dont get an error and i dont get a download into the download folder
If it has downloaded somewhere else how can i find the path it has gone to?
If you don't give path it will download in folder you run script from.
import requests
url = 'https://drive.google.com/uc?export=download&id=1o9DtaYEb1N-C_L7kqCAgfE0D5RaEwbZH'
response = requests.get(url)
with open(r'C:\Users\<your username>\Downloads\5mb.zip', 'wb') as f:
f.write(response.content)
Like this to get in download folder.
i found the file
i wasnt able to open the xlsx file
when i changed the file type to txt and opened it i have html inside and im expecting a xlsx file with order details
its not the same as when i enter the URL into a browser
i have found out that from my personal device i can run the below which will download the file to my downloads folder
import webbrowser
url = "https://blah.com/orders/downloadInvoices/2023-06-01/2023-06-27"
webbrowser.open_new(url)
what i would like to do is download the file into an object so i can then extract the content and push it into a database
how can i get the file into an object and not the html response?
Use
Code Tags.
(Jun-27-2023, 06:01 PM)JayManPython Wrote: [ -> ]when i changed the file type to txt and opened it i have html inside and im expecting a xlsx file with order details
its not the same as when i enter the URL into a browser
Then you have not find the right link for downlod,then will just get the source html.
(Jun-27-2023, 06:53 PM)JayManPython Wrote: [ -> ]what i would like to do is download the file into an object so i can then extract the content and push it into a database
A Excel file is in binary format,to get content in Python need to use eg
Pandas or
openpyxl.
Example
Notebook.
i have resolved
i had the right URL but the session wasnt logged in so i used beautiful soup to manage the login and used the same session
thank you for your help
Authentication: Ensure you have the correct credentials and that the server supports basic authentication. If the server uses a different authentication method (e.g., token-based), you'll need to adjust the request accordingly.
Error Handling: The code above checks if the response status code is 200 (OK). You might want to handle other status codes or exceptions to make your script more robust.
Date Formatting: Ensure the date format in the URL matches the server's expected format.