웹 크롤링 시 한글 깨짐 문제

하스레·2024년 4월 30일
0

오류 설명

python으로 크롤링 시 다음과 같이 한글이 깨져서 가져와짐

������ȭ �� ����� ������ ����ȭ�� ���� �Ұ�(���):�װ���� ������ �߽�����
����ü�� �Ѽ����ֱ� ��� ���Ҹ� ���� ���ձ�������(ILS) ��������(R&D) Ȱ��ȭ ����

오류 해결

'euc-kr'로 디코딩, 'utf-8'로 인코딩 해줬더니 잘 가져와진다.

    res = requests.get(f"https://...", verify=False)
    
    htmlCode = res.content.decode('euc-kr', 'replace').encode('utf-8','replace')
    soup = BeautifulSoup(htmlCode, 'html.parser')
profile
Software Developer

0개의 댓글