我正在使用scrapy和django。在清理數據時我使用:使用正則表達式編碼時出錯
html = re.sub(r'(™|®|©|™|®|©|™|®|©)', '',html, flags=re.IGNORECASE)
在正常的python shell中運行很好。但每次我嘗試運行scrapy抓取時,我得到這個錯誤:
SyntaxError: Non-ASCII character '\xe2' in file /somefile/ on line 105, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
有人可以幫助我。謝謝!
#!/usr/bin/python
# -*- coding: utf-8 -*-
確保它們放在文件的第一行:
您是否試圖提取您的搜索字符串,並明確聲明它爲unicode字符串? 'mystring = u'regexp | regexp'並在子字符串匹配中使用它? – user1603472 2015-02-23 23:44:48