Python 解析速腾快递 网点查询
本帖最后由 E飞翔 于 2018-11-21 21:26 编辑知识点,XML的解析
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() 刚开始学习Python,有参考价值 留名一个! 支持,吾爱破解 收藏了 谢谢~ 支持一下,从小做起{:1_921:} 前排占座 楼主辛苦了! 感谢楼主分享 支持一波 {:1_893:}{:1_893:}
页:
[1]