Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # ==================================================================
- # Descarga una copia del `url` y la guarda en `/tmp`
- # Sí la página no está disponible, devuelve: `HTTPError: Forbidden`.
- #
- # Devuelve un objeto con una interfaz similar a un archivo;
- # el nombre del archivo es accesible mediante su atributo 'name'.
- # El archivo se eliminará automáticamente cuando se cierre,
- # a menos que el argumento 'delete' se establezca en `False`.
- #
- # El atchivo se crea en '/tmp' con un nombre arbitrario, sin
- # estensión, con 'tipo: documento HTML (text/html)'
- # En el ejemplo: el manual de usuario de `git`
- # =================================================================
- import shutil
- import tempfile
- import urllib.request
- with urllib.request.urlopen(
- 'https://mirrors.edge.kernel.org/pub/software/scm/git/docs/user-manual.html'
- ) as response:
- with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
- shutil.copyfileobj(response, tmp_file)
- with open(tmp_file.name, encoding='utf-8') as html:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement