Herramientas de usuario

Herramientas del sitio


informatica:lenguajes_de_programacion:python:python_urrlib

¡Esta es una revisión vieja del documento!


Python UrlLib

import urllib.request
import shutil
#headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'}
headers = {'User-Agent': 'Mozilla/5.0 (Linux; Android 16; Pixel 9) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.12.45 Mobile Safari/537.36')
request = urllib.request.Request("<url>", headers=headers)
r = urllib.request.urlopen(request).read()
#print(r.decode('utf-8'))
#with open("R.json", 'w') as out:
#   shutil.copyfileobj(r, out)
with open('T.json', 'wb') as file:
   file.write(r)
informatica/lenguajes_de_programacion/python/python_urrlib.1769703964.txt.gz · Última modificación: 2026/01/29 16:26 por admin