Python requests模块解析XML

时间:2022-07-25
本文章向大家介绍Python requests模块解析XML,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

检查QQ是否在线(api感觉不准)

import requests
from xml.etree import ElementTree
qq_str = input('please input the qq that you want check!:')
url_str ='http://www.webxml.com.cn//webservices//qqOnlineWebService.asmx//qqCheckOnline?qqCode=%s'%qq_str
text_str = requests.get(url_str)
text_str.encoding='utf-8'
#解析xml格式内容,将字符串转为特殊的对象
node = ElementTree.XML(text_str.text)
if node.text == 'Y':
    print('QQ:{} 在线'.format(qq_str))
else:
    print('QQ:{} 离线'.format(qq_str))