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

请问如何使用 Python 解析如下数据,获取双引号内的数据

  •  
  •   Deteriorator · Jul 21, 2019 · 3642 views
    This topic created in 2632 days ago, the information mentioned may be changed or developed.
    这是 wordpress 数据库 wp_options 表中的主题设置,例如我用的是 dux 主题,截取一段数据如下:
    s:8:"logo_src";s:60:"http://xxx.com/LOGO.png";s:6:"layout";s:1:"2";s:10:"theme_skin";s:6:"45B6F7";

    请问我应该使用什么方法能快速获取双引号内的数据?
    8 replies  •  2019-07-21 20:09:57 +08:00
    misaka19000
        1
    misaka19000  
       Jul 21, 2019 via Android
    reg expression
    v2nika
        2
    v2nika  
       Jul 21, 2019   ❤️ 1
    这看起来像 php 的 serialize 函数的输出, 你直接找对应的函数的 python 版本就好了
    heybuddy
        3
    heybuddy  
       Jul 21, 2019 via Android   ❤️ 1
    这个是 PHP 里面的 serialize()函数序列化后的结果,貌似 Python 有个 phpserialize 的库可以使用
    Deteriorator
        4
    Deteriorator  
    OP
       Jul 21, 2019
    @v2nika 我找找看
    @misaka19000 正则不太现实,因为后面还有一大串
    Deteriorator
        5
    Deteriorator  
    OP
       Jul 21, 2019
    @heybuddy 多谢,我试一下
    jdhao
        6
    jdhao  
       Jul 21, 2019 via Android
    这种规则化的字符串很难处理吗,难点在哪里?
    orcusfox
        7
    orcusfox  
       Jul 21, 2019 via iPhone
    split(‘“‘) ?
    Deteriorator
        8
    Deteriorator  
    OP
       Jul 21, 2019
    @v2nika
    @heybuddy 感谢,用 phpserialize 库直接解码成 dictionary
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2382 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 14:29 · PVG 22:29 · LAX 07:29 · JFK 10:29
    ♥ Do have faith in what you're doing.