推荐学习书目
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
omg21
V2EX  ›  Python

字典的 value 中有引号怎么处理?

  •  
  •   omg21 · Jan 16, 2017 · 4739 views
    This topic created in 3423 days ago, the information mentioned may be changed or developed.
    {"NAME":"哈尔滨双城区"互联网+农业"高标准示范基地活动周开幕"}

    这是用 requests post 爬下来的内容,一直都好好的,但是突然 这次出了故障,检查之后发现故障出在这里, value 中的字符串中有双引号,拿到的数据就是这样,怎么好改?请问这应该怎么处理?
    9 replies    2017-01-19 15:30:18 +08:00
    tianice
        1
    tianice  
       Jan 16, 2017
    检查一下自己的程序有问题还是爬取得数据有问题,如果是爬取得数据有问题就比较麻烦了,可能需要自己写 json 解析,简单的好说,复杂的就不好写了, value 中如果再有冒号就麻烦了, key 和 value 都分不出来了
    omg21
        2
    omg21  
    OP
       Jan 16, 2017
    @tianice 不是程序的问题,这是爬下来的数据,其他字符串都排除了问题,问题就出在这个标题的引号上,
    just1
        3
    just1  
       Jan 16, 2017 via Android
    \"
    xpresslink
        4
    xpresslink  
       Jan 17, 2017
    这个还不简单,用三引号包起来,或单引号外层。 repr()
    SoloCompany
        5
    SoloCompany  
       Jan 17, 2017
    明显是你自己的爬虫程序写的有问题
    Arthur2e5
        6
    Arthur2e5  
       Jan 17, 2017
    如果输入就坏了的话,那就直接上正则硬解好了……
    omg21
        7
    omg21  
    OP
       Jan 17, 2017
    @SoloCompany
    拿到的字符串就是这样的
    {"NAME":"哈尔滨双城区"互联网+农业"高标准示范基地活动周开幕"}
    正确的写法就不会拿到这样的数据,对吗?
    zonyitoo
        8
    zonyitoo  
       Jan 17, 2017
    这个根本不是合法的 Json ,也不是 Python 。程序写得有问题,直接拼字符串拼出问题了
    omg21
        9
    omg21  
    OP
       Jan 19, 2017
    @zonyitoo 谢谢,已经搞定了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   993 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 5414617a · 79ms · UTC 22:15 · PVG 06:15 · LAX 15:15 · JFK 18:15
    ♥ Do have faith in what you're doing.