3

I tried to fetch some info from a website but got this instead .

here is the code..

import requests
r = requests.get("http://erp.college_name.edu/").text
print(r)

and here is the error..

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Users\User\AppData\Local\Programs\Python\Python35-
  32\lib\encodings\cp437.py", line 19, in encode
     return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in 
   position 7435: character maps to <undefined>

i am trying to login to my id using requests.
any help?

eLRuLL
  • 18,488
  • 9
  • 73
  • 99
P.hunter
  • 1,345
  • 2
  • 21
  • 45
  • Your `PYTHONIOENCODING` is likely not set to `UTF-8`. Please verify this by trying to `print(u'♠')`. If this throws the same exception, consult [this answer](http://stackoverflow.com/questions/25127673/how-to-print-utf-8-to-console-with-python-3-4-windows-8) – Georg Grab Mar 15 '17 at 15:29
  • @talkdirty im get6ting this `>>> print(u'♠')` ♠ it means there isnt any problem with my console, then what is it? – P.hunter Mar 15 '17 at 15:31
  • and what does it have to do with web-scraping – P.hunter Mar 15 '17 at 15:35
  • Nothing with web scraping directly, but my guess was that python had trouble displaying the content in the terminal. Since it works to you though, i was wrong here. what do you get for `r.encoding`? – Georg Grab Mar 17 '17 at 09:29

1 Answers1

4

You can encode the text with 'utf-8', then the string can be print out correctly.

import requests
r = requests.get("http://erp.college_name.edu/").text

print(r.encode('utf-8'))
YJLO
  • 81
  • 4