I am using the following code to scrape a webpage that contains Japanese characters:
import urllib2
import bs4
import time
url = 'http://www.city.sapporo.jp/eisei/tiiki/toban.html'
pagecontent = urllib2.urlopen(url)
soup = bs4.BeautifulSoup(pagecontent.read().decode("utf8"))
print(soup.prettify())
print(soup)
In some machines the code works fine, and the last two statements print the result successfully. However, in some machines the last but one statement gives the error
UnicodeEncodeError 'ascii' codec can't encode characters in position 485-496: ordinal not in range(128),
and the last statement prints strange squares for all Japanese characters.
Why the same code works differently for two machines? How can I fix this?
Python version 2.6.6
bs4 version: 4.1.0