mysql - 用Python怎么在一个字符串里面取到想要的数据?
高洛峰
高洛峰 2017-04-17 17:13:59
0
4
1073

从数据库中提取到一个字符串。
a:2:{i:27;a:6:{s:3:"did";i:27;s:3:"num";i:1;s:8:"discount";s:1:"0";s:5:"price";s:2:"40";s:4:"name";s:12:"芒果雪冰";s:5:"omark";s:0:"";}i:36;a:6:{s:3:"did";i:36;s:3:"num";i:1;s:8:"discount";s:1:"0";s:5:"price";s:2:"40";s:4:"name";s:12:"抹茶雪冰";s:5:"omark";s:0:"";}}

现在要取出其中的“芒果雪冰”跟“抹茶雪冰”,用什么方法呢。。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
伊谢尔伦

Isn’t this the result of PHP serialization? Regular expressions are the best for python

巴扎黑

Use regular expressions to match strings preceded by "s:12:" and followed by quotes.

import re
match_list = re.findall('(?<=s\:12\:)\".+?\"', s1)
Ty80

It is not recommended that you use regular expressions to extract. For regular data, the best way is to use the corresponding parsing format, which is json. It is recommended that you use json to parse directly, of course, if you need it. You can use it directly to extract Chinese.

^[u4E00-u9FA5]+$

迷茫

This is the serialization of PHP variables. There is a third-party module in Python called phpserialize that can convert it to Python data types. Specific tutorials can be found here:
Python uses PHP serialized data

If possible, please extract it yourself. Okay?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template