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

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

  •  
  •   Deteriorator · 2019-07-21 18:54:10 +08:00 · 2796 次点击
    这是一个创建于 1734 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这是 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 条回复    2019-07-21 20:09:57 +08:00
    misaka19000
        1
    misaka19000  
       2019-07-21 19:02:54 +08:00 via Android
    reg expression
    v2nika
        2
    v2nika  
       2019-07-21 19:07:40 +08:00   ❤️ 1
    这看起来像 php 的 serialize 函数的输出, 你直接找对应的函数的 python 版本就好了
    heybuddy
        3
    heybuddy  
       2019-07-21 19:10:47 +08:00 via Android   ❤️ 1
    这个是 PHP 里面的 serialize()函数序列化后的结果,貌似 Python 有个 phpserialize 的库可以使用
    Deteriorator
        4
    Deteriorator  
    OP
       2019-07-21 19:12:17 +08:00
    @v2nika 我找找看
    @misaka19000 正则不太现实,因为后面还有一大串
    Deteriorator
        5
    Deteriorator  
    OP
       2019-07-21 19:12:39 +08:00
    @heybuddy 多谢,我试一下
    jdhao
        6
    jdhao  
       2019-07-21 19:31:00 +08:00 via Android
    这种规则化的字符串很难处理吗,难点在哪里?
    napsterwu
        7
    napsterwu  
       2019-07-21 19:35:37 +08:00 via iPhone
    split(‘“‘) ?
    Deteriorator
        8
    Deteriorator  
    OP
       2019-07-21 20:09:57 +08:00
    @v2nika
    @heybuddy 感谢,用 phpserialize 库直接解码成 dictionary
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2900 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:52 · PVG 11:52 · LAX 20:52 · JFK 23:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.