Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #change #order #attributes #element #beautiful #soup
ADD COMMENT
Topic
Name
6+4 =