随堂笔记1
用正则表达式,获取img元素中的src里的内容:
a ='SUVwwwyyy我<img alt="" src="http://123/im/fat/43/fa435d1dc0f782eda5f44bb5c31a9515.jpg" width="100%" /><img alt="" src="http://123/im/7c/75/7c75839afb2538a0eccba6bf160f6a03.jpg" width="100%" /><img alt="" src="http://123/im/26/cf/26cf6e784c4536f9264f844f4f5a8e83.jpg" width="100%" /><img alt="" src="http://123/im/af/aa/afaaf3fb997826078c0842043bc2c291.jpg" width="100%" /><img alt="" src="http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg" width="100%" /><img alt="" src="http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg" width="100%" /><img alt="" src="http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg" width="100%" /><img alt="" src="http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg" width="100%" /><img alt="" src="http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg" width="100%" />'
re_img1 = re.findall('<img.*?src="(.*?)".*?/>',a)
print(re_img1)
跑出来的结果:
['http://123/im/fat/43/fa435d1dc0f782eda5f44bb5c31a9515.jpg', 'http://123/im/7c/75/7c75839afb2538a0eccba6bf160f6a03.jpg', 'http://123/im/26/cf/26cf6e784c4536f9264f844f4f5a8e83.jpg', 'http://123/im/af/aa/afaaf3fb997826078c0842043bc2c291.jpg', 'http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg', 'http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg', 'http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg', 'http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg', 'http://123/cache/im/afaaf3fb997826078c0842043bc2c291.jpg']
拼接字符串:
newuri=x+","+newuri
去除字符串最后一个字符:
newuri[:-1]
转json格式:
import json
if stickerId is not None:
denfo = {'theId': theId, 'stickList': [{'stickId': stickId, 'px': px,
'py': py,'rotate': rotate,
'aling': aling,'mir': mir,'inZ':inz}]}
decorateInfo = json.dumps(denfo)
else:
denfo = {'theId': theId,'stickList':[]}
decorateInfo = json.dumps(deInfo)
浙公网安备 33010602011771号