I found a very useful Python package for detecting the encoding of files. It's chardet.
1. install chardet
pip install chardet
2. an example of how to use it
Python 2
import urllib
rawdata = urllib.urlopen("http://www.baidu.com").read()
import chardet
chardet.detect(rawdata)
Python 3
from urllib.request import urlopen
rawdata = urlopen("http://www.baidu.com").read()
import chardet
print (chardet.detect(rawdata))
3. results