I'm trying to scrape a website, but it gives me an error.I'm using the following code: import urllib.requestfrom bs4 import BeautifulSoupget = urllib.request.urlopen('= get.readsoup = BeautifulSoup(html)print(soup)And I'm getting the following error: File 'C:Python34libencodingscp1252.py', line 19, in encodereturn codecs.charmapencode(input,self.errors,encodingtable)0UnicodeEncodeError: 'charmap' codec can't encode characters in position 0: character maps to What can I do to fix this? In Python 3.7, and running Windows 10 this worked (I am not sure whether it will work on other platforms and/or other versions of Python)Replacing this line:with open('filename', 'w') as f:With this:with open('filename', 'w', encoding='utf-8') as f:The reason why it is working is because the encoding is changed to UTF-8 when using the file, so characters in UTF-8 are able to be converted to text, instead of returning an error when it encounters a UTF-8 character that is not suppord by the current encoding. While saving the response of get request, same error was thrown on Python 3.7 on window 10.
![Codex Codex](http://4.bp.blogspot.com/-OBqR9w7xVC4/VdvAGvFu6zI/AAAAAAAAFqg/Exg7PPxev1A/s1600/Ranger-CharacterClass.jpg)
The response received from the URL, encoding was UTF-8 so it is always recommended to check the encoding so same can be passed to avoid such trivial issue as it really kills lots of time in production import requestsresp = requests.get('open ('NiftyList.txt', 'w') as f:f.write(resp.text)When I added encoding='utf-8' with the open command it saved the file with the correct response with open ('NiftyList.txt', 'w', encoding='utf-8') as f:f.write(resp.text).
Character ยป Codex appears in 9 issues. Codex is the online role playing identity created by emotionally-troubled violinist Cyd Sherman. She is a human, neutral good cleric, and wields a powerful.