# coding=utf-8
__author__ = 'zhanghe'
import re
import json
test_html = '''
- 工作年限:
-
应届毕业生
- 居住地:
-
清远
- 求职状态:
-
目前正在找工作
- 身高:
-
180cm
- 婚姻状况:
-
'''
def re_html(html):
"""
通过正则表达式获取关键数据
将两个有序的列表组合为无序的字典
:param html:
:return:
"""
reg_dt = r'(.+?):'
reg_dd = r'(.+?)
'
dt = re.compile(reg_dt)
dd = re.compile(reg_dd)
dt_list = re.findall(dt, html)
dd_list = re.findall(dd, html)
zip_list = zip(dt_list, dd_list)
html_dict = dict((name, value) for name, value in zip_list)
return json.dumps(html_dict, ensure_ascii=False, indent=4)
if __name__ == '__main__':
print re_html(test_html)