beautifulsoup - UnicodeEncodeError when printing beautifulsoup4 get_text() in Python -


i'm running pretty simple script in python data url:

import urllib2 bs4 import beautifulsoup  def get_data():      response = urllib2.urlopen('http://www.p2016.org/photos15/summit/trump012415spt.html')     html = beautifulsoup(response, 'html.parser')     text = html.get_text()     return text   print get_data() 

i keep getting error message:

ps c:\users\ben\pythonlearning\markov_chain> python fetch_data.py traceback (most recent call last):   file "fetch_data.py", line 11, in <module>     print get_data()   file "c:\python27\lib\encodings\cp437.py", line 12, in encode     return codecs.charmap_encode(input,errors,encoding_map) unicodeencodeerror: 'charmap' codec can't encode character u'\xa9' in position 22825: character maps <undefined> 

i've tried:

  • running without print command, , no error
  • having on computer run exact same code, , works.

the difference encounter between error , "having on computer run exact same code, , works" due differing versions of cpython interpreter.

python 3 marks significant backwards-incompatible change in language features, , that's why error.

you can confirm difference running command on both platforms:

python -c 'import sys; print(sys.version)' 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -