XML parser is not working

Discussion in 'Simplilearn Support' started by ROHIT RANJAN SRIVASTAVA, Apr 6, 2020.

  1. ROHIT RANJAN SRIVASTAVA

    Joined:
    Mar 4, 2020
    Messages:
    10
    Likes Received:
    0
    XML parser is not working when I am using BeautifulSoup.
    Kindly help to rectify.
    Regards
    Rohit

    soup.body.a.prettify(formatter = 'xml')
    Error Message:
    ---------------------------------------------------------------------------
    KeyError Traceback (most recent call last)
    <ipython-input-9-922ba9e52614> in <module>
    ----> 1soup.body.a.prettify(formatter = 'xml')

    ~\Anaconda3\lib\site-packages\bs4\element.py in prettify(self, encoding, formatter)
    1175 def prettify(self, encoding=None, formatter="minimal"):
    1176 if encoding is None:
    -> 1177return self.decode(True, formatter=formatter)
    1178 else:
    1179 return self.encode(encoding, True, formatter=formatter)

    ~\Anaconda3\lib\site-packages\bs4\element.py in decode(self, indent_level, eventual_encoding, formatter)
    1088 # over again.
    1089 if not isinstance(formatter, Formatter):
    -> 1090formatter = self.formatter_for_name(formatter)
    1091 attributes = formatter.attributes(self)
    1092 attrs = []

    ~\Anaconda3\lib\site-packages\bs4\element.py in formatter_for_name(self, formatter)
    161 if callable(formatter):
    162 return c(entity_substitution=formatter)
    --> 163return c.REGISTRY[formatter]
    164
    165 @property

    KeyError: 'xml'
     
    #1
  2. Raghavendra B M

    Raghavendra B M Active Member
    Simplilearn Support

    Joined:
    Jan 6, 2020
    Messages:
    44
    Likes Received:
    34
    Hi Rohit,

    Kindly install 'lxml' by using pip install lxml and provide fromatter as 'lxml'.

    This will fix the issue.

    I hope this helped you. Happy Learning.

    Regards,
    Raghavendra BM
    GTA
     
    #2

Share This Page