Fetch a website (Python)

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 4 feb 2019 om 21:49 (Nieuwe pagina aangemaakt met '<pre> #! /usr/bin/python3 # # Download Channable-XML-file - Strompf, Feb. 2019 ############################################################################## # impo...')
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen
#! /usr/bin/python3
#
# Download Channable-XML-file - Strompf, Feb. 2019
##############################################################################
#
import urllib.request


url = 'https://www.example.com/fr-fr_channable.xml'
response = urllib.request.urlopen(url)
data = response.read()      # a `bytes` object
text = data.decode('utf-8') # a `str`; this step can't be used if data is binary

print(text)

Bronnen