Adicionando "encoding" no BeautifulSoup 4 para evitar problemas com caracteres

This commit is contained in:
Luiz Otávio
2023-01-24 10:32:17 -03:00
parent 41f6d513ad
commit d2280a46aa

View File

@@ -14,8 +14,8 @@ from bs4 import BeautifulSoup
url = 'http://127.0.0.1:3333/' url = 'http://127.0.0.1:3333/'
response = requests.get(url) response = requests.get(url)
raw_html = response.text bytes_html = response.content
parsed_html = BeautifulSoup(raw_html, 'html.parser') parsed_html = BeautifulSoup(bytes_html, 'html.parser', from_encoding='utf-8')
# if parsed_html.title is not None: # if parsed_html.title is not None:
# print(parsed_html.title.text) # print(parsed_html.title.text)