Python Forum
Access my webpage and download files from Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access my webpage and download files from Python
#1
I have a godaddy webpage. I don't use it much. Mainly just for trying things out.

I have managed enough PHP to get files uploaded to my webhost from a webpage. The user just clicks a button to select a file, then clicks the upload button

The PHP to validate the files, pack them in an email and send them seems quite complex. Too much for me! I need to install PHPMailer or Pear on the server and do all kinds of complicated stuff it seems. Python to the rescue!

I found I can get a file simply like this:

import requests 
file_url = "http://www.mywebpage.com/php/uploads/chineseYearAnimals.txt"
  
# URL of the files to be downloaded is defined as file_url 

r = requests.get(file_url) # create HTTP response object 
  
# send a HTTP request to the server and save 
# the HTTP response in a response object called r 
with open("/home/pedro/Downloads/download1.txt",'wb') as f: 
  
    # Saving received content as a file in 
    # binary format 
  
    # write the contents of the response (r.content) 
    # to a new file in binary mode. 
    f.write(r.content)
    f.close()
Could you please help me modify this?

I want to

1. download all files in the path,
2. save them under whatever name they already have,
3. then delete them on the web server.

On my laptop, when I want to do something with all files in a directory, I use:

Quote:files = os.listdir(path)

and then:

Quote:for file in files:
do tricky stuff
I need the web version of that.
Reply


Messages In This Thread
Access my webpage and download files from Python - by Pedroski55 - May-25-2019, 02:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to access text files, hidden behind 'm3u8' resources Pavel_47 4 2,269 Feb-19-2023, 02:47 PM
Last Post: Pavel_47
  Using range slider in flask webpage to use in python KimPet 2 7,674 Jan-23-2021, 11:58 PM
Last Post: snippsat
  How to access a web service from a python script? dangermaus33 6 3,232 Dec-04-2020, 07:04 AM
Last Post: dangermaus33
  Download some JPG files and make it a single PDF & share it rompdeck 5 5,715 Jul-31-2020, 01:15 AM
Last Post: Larz60+
  Python values on a WebPage Petrouil 1 1,923 Apr-01-2020, 05:08 PM
Last Post: ndc85430
  Read Save RadioButtons from Database in Python Flask Webpage Gary8877 0 7,185 Apr-11-2019, 12:33 AM
Last Post: Gary8877
  display multiple sensors on webpage python flask jinja pascale 6 5,283 Jan-29-2019, 10:10 AM
Last Post: pascale
  I wan't to Download all .zip Files From A Website (Project AI) eddywinch82 68 38,308 Oct-28-2018, 02:13 PM
Last Post: eddywinch82
  I Want To Download Many Files Of Same File Extension With Either Wget Or Python, eddywinch82 15 14,623 May-20-2018, 06:05 PM
Last Post: eddywinch82
  Login in a Webpage using a python program sumandas89 2 12,282 Dec-21-2017, 01:43 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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