| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import urllib.request
- from lxml import etree # @UnresolvedImport
- class WSParser():
- """ Parser for a web service """
- def __init__(self, url):
- self._url = url
- self._data = None
- @property
- def url(self):
- return self._url
- def parse(self):
- strxml = urllib.request.urlopen(self._url).read()
- self._data = etree.fromstring(strxml)
- def __iter__(self):
- if self._data is None:
- self.parse()
- return (node.attrib for node in self._data)
- # OU
- #
- # from _io import BytesIO
- # URL = 'http://localhost:2890/public/WsPDE.asmx/GetPDETitres'
- #
- # data = urllib.request.urlopen(URL).read()
- #
- # for _, element in etree.iterparse(BytesIO(data)):
- # print(element.attrib)
- if __name__ == "__main__":
- ws_url = 'http://localhost:2890/public/WsPDE.asmx/GetPDETitres'
- for elt in WSParser(ws_url):
- print(elt)
|