本文介绍了在Python中解析mailto网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将mailto URL解析为一个不错的对象或词典,其中包括 subject
, body
等.我似乎找不到一个库或类可以达到这个目的-您知道吗?
I'm trying to parse mailto URLs into a nice object or dictionary which includes subject
, body
, etc. I can't seem to find a library or class that achieves this- Do you know of any?
mailto:[email protected]?subject=mysubject&body=mybody
推荐答案
似乎您可能只想编写自己的函数即可.
Seems like you might just want to write your own function to do this.
这是一个示例函数(由python noob编写).
Here is a sample function (written by a python noob).
编辑 2,对反馈进行清理:
Edit 2, cleanup do to feedback:
from urllib import unquote
test_mailto = 'mailto:[email protected]?subject=mysubject&body=mybody'
def parse_mailto(mailto):
result = dict()
colon_split = mailto.split(':',1)
quest_split = colon_split[1].split('?',1)
result['email'] = quest_split[0]
for pair in quest_split[1].split('&'):
name = unquote(pair.split('=')[0])
value = unquote(pair.split('=')[1])
result[name] = value
return result
print parse_mailto(test_mailto)
这篇关于在Python中解析mailto网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!