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
csx163
V2EX  ›  Python

请问为什么抓取数据时字符会a变b,双引号变#号等

  •  
  •   csx163 · 2013-07-29 11:13:50 +08:00 · 3592 次点击
    这是一个创建于 3925 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在使用urllib2抓取数据时, 对方是gbk编码先转编码

    str=decode('gb18030').encode('utf8')
    MySQLdb.escape_string(str)

    其他无任何处理了

    最后用utf8存入了mysql

    但每几千条会碰到一个字符错误,不是a变成b,就是"号变为#号,由于是xml,就变得根本无法解析

    请问问题出在哪里呢?
    3 条回复    1970-01-01 08:00:00 +08:00
    yautou
        1
    yautou  
       2013-07-29 12:23:13 +08:00
    我以前是傻傻的正则替换,然后忘了现在正确的解决办法=。=
    jerntseedee
        2
    jerntseedee  
       2013-08-21 12:03:11 +08:00
    你好,我在一篇关于portal认证的帖子中看到了你的回复。想请问你对创业有没有兴趣?我的英雄帖,不妨关注下哈:http://www.v2ex.com/t/79537
    GordianZ
        3
    GordianZ  
    MOD
       2013-08-21 12:44:50 +08:00
    @jerntseedee 请不要劫持主题,警告一次。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1462 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:06 · PVG 01:06 · LAX 10:06 · JFK 13:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.