V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
loginv2
V2EX  ›  Python

请问 stripogram 的 html2text 功能在碰到 这样的字符的时候出错怎么解决

  •  
  •   loginv2 · 2014-11-20 15:19:05 +08:00 · 2494 次点击
    这是一个创建于 3459 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # -*- coding: UTF-8 -*-
    import codecs,time,urllib2,re,random,sys
    from stripogram import html2text, html2safehtml
    reload(sys)
    sys.setdefaultencoding( "utf-8" )

    html = '''<div> <span>10月25日</span></div>'''
    print html.decode("utf-8")
    print html2text(html).decode("utf-8")



    Traceback (most recent call last):
    File "C:\Users\new 1.py", line 9, in <module>
    print html2text(html).decode("utf-8")
    File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 0: invalid start byte
    1 条回复    2014-11-20 15:21:48 +08:00
    loginv2
        1
    loginv2  
    OP
       2014-11-20 15:21:48 +08:00
    啊咧咧,V2竟然过滤掉了 昏倒 <div> <span>之间有一个nbsp的空格字符
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1137 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 22:53 · PVG 06:53 · LAX 15:53 · JFK 18:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.