UnicodeEncodeErrorを:「ASCII」コーデックは、文字をエンコードすることはできませんか?

StackOverflow https://stackoverflow.com/questions/1653569

質問

私は、正規表現によるランダムなHTMLの大きな文字列を渡すためにしようとしていると私はPython 2.6のスクリプトは、この上で窒息されます:

UnicodeEncodeErrorを: 'ASCII' コーデックが文字をエンコードすることはできません。

私はこの言葉の端にバック商標上付き文字にそれをトレースする:保護™ - 私は、非ASCIIのものをキャプチャする必要はありませんが、それは迷惑であると私は将来的にはより多くのそれに出会うことを期待しています。

非ASCII文字を処理するモジュールはありますか?または、処理するための最良の方法は何か/ pythonで非ASCIIのものをエスケープ?

ありがとう! 完全なエラーます:

E
======================================================================
ERROR: test_untitled (__main__.Untitled)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python26\Test2.py", line 26, in test_untitled
    ofile.write(Test + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2122' in position 1005: ordinal not in range(128)

全スクリプトます:

from selenium import selenium
import unittest, time, re, csv, logging

class Untitled(unittest.TestCase):
    def setUp(self):
        self.verificationErrors = []
        self.selenium = selenium("localhost", 4444, "*firefox", "http://www.BaseDomain.com/")
        self.selenium.start()
        self.selenium.set_timeout("90000")

    def test_untitled(self):
        sel = self.selenium
        spamReader = csv.reader(open('SubDomainList.csv', 'rb'))
        for row in spamReader:
            sel.open(row[0])
            time.sleep(10)
            Test = sel.get_text("//html/body/div/table/tbody/tr/td/form/div/table/tbody/tr[7]/td")
            Test = Test.replace(",","")
            Test = Test.replace("\n", "")
            ofile = open('TestOut.csv', 'ab')
            ofile.write(Test + '\n')
            ofile.close()

    def tearDown(self):
        self.selenium.stop()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
scroll top