0

Is there any xml parser other than BS4 and LXML that I can use?

I cannot pip install BS4 and LXML in the environment I am in, but I would need to do some simple xml parsing - getting node by id or name, get or set attribute values of a node and etc.

Is there any other library that I can use?

Kay
  • 1,235
  • 2
  • 13
  • 27
  • 2
    I disagree with the votes to close. This isn't asking for a general tool question like "LOL I don't like to read and want to know what web framework to use", but asking for specific information about a standard Python installation. – Kirk Strauser Jan 23 '21 at 00:03
  • 1
    I was going to answer this: there are several [built-in XML parsers](https://docs.python.org/2.7/library/xml.html). In particular, [xml.etree.ElementTree](https://docs.python.org/2.7/library/xml.etree.elementtree.html#module-xml.etree.ElementTree) may be useful in your situation. – Kirk Strauser Jan 23 '21 at 00:03
  • Thank you very much for your help. I will try your suggestion. I agree with you about closing this question. – Kay Jan 23 '21 at 00:23
  • 1
    @Kirk Strauser, I find xml.etree.ElementTree quite capable with proper use of XPath. Thank you very much! – Kay Jan 23 '21 at 21:25
  • 1
    Awesome! Happy hacking, @Kay! – Kirk Strauser Jan 24 '21 at 05:58
  • @Kirk Strauser, is there html parser that I can use for similar purpose? I tried html.parser, but is very different. I just need to get nodes by id or names, get or set attribute values of a node and etc. – Kay Jan 25 '21 at 06:12
  • 1
    Sorry, @Kay: that's the only one I know of that's likely to be available in your setup. You could probably _get_ values using regular expressions or string matching as long as the input HTML is reasonably consistent, but I don't know of anything built-in that would let you easily modify the document. – Kirk Strauser Jan 25 '21 at 17:27
  • 1
    @Kay Recommend you a simple library: https://github.com/yiyedata/simplified-scrapy-demo/blob/master/doc_examples/get_element.py – dabingsou Jan 26 '21 at 02:24
  • @dabingsou, Thank you so much for the recommendation. I am trying it right now. – Kay Jan 26 '21 at 19:50
  • Thank you guys all for helping through this closed question. I really appreciate your recommendations and suggestions. – Kay Jan 26 '21 at 19:54

0 Answers0