Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
download a file from a URL
#1
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
Reply
#2
Look at a basic is in this Post,testet now still work.
Reply
#3
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)
Reply
#4
(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.
Reply
#5
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
Reply
#6
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?
Reply
#7
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.
Reply
#8
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FTP Download of Last File jland47 4 407 Mar-16-2024, 09:15 AM
Last Post: Pedroski55
  FTP File Download question / concern cubangt 3 1,318 Jan-06-2022, 07:46 PM
Last Post: cubangt
  download with internet download manager coral_raha 0 2,967 Jul-18-2021, 03:11 PM
Last Post: coral_raha
  download file from url fernandosianet 3 2,325 Oct-29-2020, 03:22 AM
Last Post: bowlofred
  Download file from Private GitHub rep vinuvt 0 1,981 Jul-27-2020, 11:38 AM
Last Post: vinuvt
  PyDrive download file path MiniMinnow 0 3,250 Apr-28-2020, 03:01 PM
Last Post: MiniMinnow
  download file from google drive .. evilcode1 7 13,884 Sep-21-2018, 06:13 PM
Last Post: evilcode1
  Download entire web pages and save them as html file with urllib.request fyec 2 14,730 Jul-13-2018, 10:12 AM
Last Post: Larz60+
  download dataset from SH file Felix 1 2,606 Mar-28-2018, 05:04 AM
Last Post: Larz60+
  Download file from Internet Tribunal 1 2,786 Oct-11-2017, 06:03 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020