1、json 

通过Python的json模块,可以将字符串形式的json数据转化为字典,也可以将Python中的字典数据转化为字符串形式的json数据。

之前使用这个模块时,都是随用随查,浅尝辄止,对模块的功能了解不深。

随着使用次数的增加,我对这个功能完善的模块有了更多的了解,记录如下。

json.loads 将字符串装换成python基本数据类型

json.dumps 将python数据类型转换成字符串方式返回

json
a = {:}
(a,(a))
c = json.dumps(a)
(c,(c))
输出
{'cao': 'jiao'} 
{"cao": "jiao"} 




获取列车时刻表
from xml.etree import ElementTree as ET
r = requests.get('http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx/getDetailInfoByTrainCode?TrainCode=G666&UserID=')
result = r.text

# 解析XML格式内容
root = ET.XML(result)
for node in root.iter('TrainDetailInfo'):
    print(node.find('TrainStation').text,node.find('StartTime').text,node.tag,node.attrib)