심.소.남(PythonCrawling, React, Node_Js)_1)UnicodeEncodeError: 'cp949' codec can't encode character '\xa0' in position 778: illegal multibyte sequence

오범준·2020년 12월 7일
0

1) Aladin Data Crawling

problem

Traceback (most recent call last):
  File "c:\Users\user.DESKTOP-3NN2QR0\Desktop\CodingStudyStuff\web_study-master\JS\Inflearn\React\Node_React_Psyche\Crawling\aladin.py", line 13, in <module>
    print(dom.text)
UnicodeEncodeError: 'cp949' codec can't encode character '\xa0' in position 778: illegal multibyte sequence

code

# -*- encoding: utf-8 -*-
import requests
from bs4 import BeautifulSoup

url = "https://www.aladin.co.kr/m/msearch.aspx?SearchWord=%EC%8B%A4%EC%A1%B4%EC%A3%BC%EC%9D%98&SearchTarget=All"

# 2. request, response
response = requests.get(url)
print(response)

dom = BeautifulSoup(response.content, "html.parser")
print(dom.text)

solution

add below code

# -*- encoding: utf-8 -*-
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')
profile
Dream of being "물빵개" ( Go abroad for Dance and Programming)

0개의 댓글

관련 채용 정보