Character encoding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mp

    #1

    Character encoding

    I have html document titles with characters like >,  , and
    &#135. How do I decode a string with these values in Python?

    Thanks

  • i80and

    #2
    Re: Character encoding

    I would suggest using string.replace. Simply replace '&nbsp' with ' '
    for each time it occurs. It doesn't take too much code.

    On Nov 7, 1:34 pm, "mp" <mailpitc...@em ail.comwrote:
    I have html document titles with characters like &gt;, &nbsp;, and
    &#135. How do I decode a string with these values in Python?
    >
    Thanks

    Comment

    • mp

      #3
      Re: Character encoding

      I'd prefer a more generalized solution which takes care of all possible
      ampersand characters. I assume that there is code already written which
      does this.

      Thanks

      i80and wrote:
      I would suggest using string.replace. Simply replace '&nbsp' with ' '
      for each time it occurs. It doesn't take too much code.
      >
      On Nov 7, 1:34 pm, "mp" <mailpitc...@em ail.comwrote:
      I have html document titles with characters like &gt;, &nbsp;, and
      &#135. How do I decode a string with these values in Python?

      Thanks

      Comment

      • Gabriel Genellina

        #4
        Re: Character encoding

        At Tuesday 7/11/2006 17:10, mp wrote:
        >I'd prefer a more generalized solution which takes care of all possible
        >ampersand characters. I assume that there is code already written which
        >does this.
        Try the htmlentitydefs module


        --
        Gabriel Genellina
        Softlab SRL

        _______________ _______________ _______________ _____
        Correo Yahoo!
        Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
        ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

        Comment

        • jiang.haiyun@gmail.com

          #5
          Re: Character encoding


          Dennis Lee Bieber wrote:
          On 7 Nov 2006 11:34:32 -0800, "mp" <mailpitches@em ail.comdeclaime d the
          following in comp.lang.pytho n:
          >
          I have html document titles with characters like &gt;, &nbsp;, and
          &#135. How do I sddecode a string with these values in Python?
          >
          Wouldn't HTMLParser be suited for such activity?
          --
          Wulfraed Dennis Lee Bieber KD6MOG
          wlfraed@ix.netc om.com wulfraed@bestia ria.com

          (Bestiaria Support Staff: web-asst@bestiaria. com)
          HTTP://www.bestiaria.com/
          Use htmlentitydefs and SGMLParser to re-generate it .

          Comment

          • Frederic Rentsch

            #6
            Re: Character encoding

            mp wrote:
            I have html document titles with characters like &gt;, &nbsp;, and
            &#135. How do I decode a string with these values in Python?
            >
            Thanks
            >
            >
            This is definitely the most FAQ. It comes up about once a week.

            The stream-editing way is like this:
            >>import SE
            >>HTM_Decoder = SE.SE ('htm2iso.se') # Include path
            >>test_string = '''I have html document titles with characters like &gt;, &nbsp;, and
            ‡. How do I decode a string with these values in Python?'''
            >>print HTM_Decoder (test_string)
            I have html document titles with characters like >, , and
            ‡. How do I decode a string with these values in Python?

            An SE object does files too.
            >>HTM_Decoder ('with_codes.tx t', 'translated_cod es.txt') # Include path
            You could download SE from -http://cheeseshop.python.org/pypi/SE/2.3. The translation definitions file "htm2iso.se " is included. If you open it in your editor, you can see how to write your own definition files for other translation tasks you may have some other time.

            Regards

            Frederic



            Comment

            Working...