本文来源吾爱破解论坛
本帖最后由 E飞翔 于 2018-11-21 21:26 编辑
知识点,XML的解析
[Python] 纯文本查看 复制代码
import requests import xml.etree.ElementTree as ET class STE_XML: wrod = '' begin = 0 max_num = 0 def __init__(self, data): self.wrod = data self.getPage() def getPage(self): """ 获取符合关键字的页码 """ datas = { 'selectColumnVal': '', 'word': self.wrod, 'begin': self.begin } res = requests.post("http://www.ste56.com.cn:8313/NewSearchPaiSongWeb/search.do", data=datas).text root = ET.fromstring(res) self.max_num = len(root) return root # for u in range(len(root)): def getAllData(self): """ 获取并且打印所有搜索到的数据 """ for u in range(self.max_num): root = self.getPage() if self.begin <= self.max_num: self.begin += 1 for a in root: for i in a: print(i.text) def getWordData(self): """ 获取关键字为站点名的数据集合 """ for u in range(self.max_num): root = self.getPage() if self.begin <= self.max_num: self.begin += 1 for a in root: for i in a: if i.text == self.wrod: return a def readWordData(self): data = self.getWordData() for i in data: print(i.text) if __name__ == '__main__': p = STE_XML("虎门") p.readWordData()
版权声明:
本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。