Answers for "how to change order of attributes of an element using beautiful soup"

0

how to change order of attributes of an element using beautiful soup

from simplified_scrapy.simplified_doc import SimplifiedDoc
html ='''
<word form="συ" head="2610" id="2357" lemma="συ" postag="p-s----n-" relation="ExD_AP"/>
'''
def toString(ele):
  order = ['id','head','postag','from','lemma','relation']
  result = '<'+ele.tag
  for p in order:
    result+=' {}="{}"'.format(p,ele[p])
  return result+'/>'
doc = SimplifiedDoc(html)
ele = doc.word
print (toString(ele))
Posted by: Guest on September-03-2021

Code answers related to "how to change order of attributes of an element using beautiful soup"

Python Answers by Framework

Browse Popular Code Answers by Language