Ошибка (кодировки) при открытии файла html в python

Есть вот такой код:

r = requests.get(url)
with open('text.html', 'w') as output_file:
    output_file.write(r.text)

На него выдаётся такая ошибка:

UnicodeEncodeError: 'charmap' codec can't encode character '\xb2' in position 5649: character maps to <undefined>

Пытался сделать так:

with open('text.html', 'w', 'utf-8') as output_file:
    output_file.write(r.text)

Выдаётся такая ошибка:

TypeError: an integer is required (got type str)

Пытался найти ответ на python.org - не нашёл


Ответы (1 шт):

Автор решения: Namerek
r = requests.get(url)
with open('text.html', 'wb') as output_file:
    output_file.write(r.content)
→ Ссылка