Jump to content
Nokioteca Forum

Python download pdf file python automatico


herman90
 Share

Recommended Posts

Salve, ho fatto una prova come lo vedete..

vorrei inserire in un bot di telegram.. c'è qualcosa che non va, ma non riesco a capire . 

 

Un aiutino?! grazie 

 

 

 

import requests
import telebot
x="..........................................................................."
alfa=telebot.TeleBot(x)
downloadLink = 'https://docs.python.it/paper-a4/tut.pdf'

req = requests.get(downloadLink)
filename = req.url[downloadLink.rfind('/')+1:]

with open(filename, 'wb') as f:
    for chunk in req.iter_content(chunk_size=8192):
        if chunk:
            f.write(chunk)

def download_file(url, filename=''):
    try:
        if filename:
            pass            
        else:
            filename = req.url[downloadUrl.rfind('/')+1:]

        with requests.get(url) as req:
            with open(filename, 'wb') as f:
                for chunk in req.iter_content(chunk_size=8192):
                    if chunk:
                        f.write(chunk)
            return filename
    except Exception as e:
        print(e)
        return None
 
alfa.polling()

Link to comment
Condividi su altri siti

Please sign in to comment

You will be able to leave a comment after signing in



Accedi Ora
 Share

×
×
  • Crea Nuovo...

Informazione Importante

Questo sito utilizza i cookie per analisi, contenuti personalizzati e pubblicità. Continuando la navigazione, accetti l'utilizzo dei cookie da parte nostra | Privacy Policy