Python, downloading file on a given day and time

Asked

Viewed 76 times

0

I’m looking to structure a Python program that downloads files (manga) from a given site once a week. I’m training, I took the course of web scraping, but I am lost on how to perform these requests. I took as an example, the code of this page

import urllib2
import requests

url = 'http://www.carlissongaldino.com.br/modules/pubdlcnt/pubdlcnt.php?file=http://www.carlissongaldino.com.br/sites/default/files/o-fantasma-da-opera.pdf&nid=1287'

print "baixando com urllib"
urllib.urlretrieve(url, "o-fantasma-da-opera-u.pdf")

print "baixando com urllib2"
f = urllib2.urlopen(url)
data = f.read()
with open("o-fantasma-da-opera-u2.pdf", "wb") as code:
    code.write(data)

print "baixando com requests"
r = requests.get(url)
with open("o-fantasma-da-opera-r.pdf", "wb") as code:
    code.write(r.content)

It teaches to download a particular file using the following libraries. I see a pattern, I think it would work, I just need to implement the day and the time. I’m lost in this part. How can you help me clear up this case?

  • 3

    Why not use a scheduled task via CRON?

  • And, how would this use?

  • I am new to programming, I am conducting experiments. I want to evolve this program. This code I took as an example, is valid for this task I want to perform?

  • I can use this cron and crontab in this already structured program?

  • Then, the code you placed does the same thing 3 times, with different modules. The simplest is the last, with requests. And yes, having the program working, just schedule its execution in CRON that it will always run at the set time.

  • Great! And, as this cron would enter in the program, I had not used this request. First time I see.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.