UnicodeEncodeError: 'charmap' codec can't encode characters

后端 未结 8 712
感情败类
感情败类 2020-11-22 11:55

I\'m trying to scrape a website, but it gives me an error.

I\'m using the following code:

import urllib.request
from bs4 import BeautifulSoup

get =          


        
8条回答
  •  误落风尘
    2020-11-22 12:23

    Even I faced the same issue with the encoding that occurs when you try to print it, read/write it or open it. As others mentioned above adding .encoding="utf-8" will help if you are trying to print it.

    soup.encode("utf-8")

    If you are trying to open scraped data and maybe write it into a file, then open the file with (......,encoding="utf-8")

    with open(filename_csv , 'w', newline='',encoding="utf-8") as csv_file:

提交回复
热议问题