主要掌握
tag
attrib
find
iter
iter
set
get
import requests
from xml.etree import ElementTree as et
r=requests.get('http://www.webxml.com.cn//webservices
/qqOnlineWebService.asmx/qqCheckOnline?qqCode=326533970')
# 查看qq是否在线
# print(r)
result=r.text
print(result)
node = et.XML(result)
# print(node)
# print(node.text)
import requests
from xml.etree import ElementTree as et
r=requests.get('http://www.webxml.com.cn/WebServices
/TrainTimeWebService.asmx/getDetailInfoByTrainCode?TrainCode=K234&UserID=')
result=r.text
root=et.XML(result) # 解析xml格式内容
for i in root.iter('TrainDetailInfo'):
print(i.find('TrainStation').text,i.find('StartTime').text)
# .text代表<>这里的内容<>
# find 能找到指定的被<><>围住的内容