我的代码:
import xbmcgui
import xbmcaddon
import urllib, urllib2, re, HTMLParser, os
from bs4 import BeautifulSoup
pg_source = ''
req = urllib2.Request('http://rushmore.tv/schedule')
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36')
try:
response = urllib2.urlopen(req)
pg_source = response.read().decode('utf-8' , 'ignore')
response.close()
except:
pass
content = []
soup = BeautifulSoup(pg_source)
content = BeautifulSoup(soup.find('ul', { 'id' : 'myUL' }).prettify())
print (content.text)
我正在尝试修复通过Kodi运行此代码时遇到的ascii错误。
通过Kodi运行此代码时,我收到以下错误消息。
Error Type: <type 'exceptions.UnicodeEncodeError'>
Error Contents: 'ascii' codec can't encode character u'\xe1' in position 1447: ordinal not in range(128)
Traceback (most recent call last):
File "C:\Users\hp\AppData\Roaming\Kodi\addons\script.test.test\main.py", line 23, in <module>
print (content.text)
File "<string>", line 7, in write
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 1447: ordinal not in range(128)
任何人都可以帮我解决这个问题吗? TY