Hi agaim,
after climbing the html tree up and down i've collected everything i need. In certain cases i now want to insert a new element right below the body element.
Code:
soup = BeautifulSoup('<body></body>')
body = soup.body
new_tag = soup.new_tag('h1')
body.append(new_tag)
print(body)
So far so good. But the inserted tag does have a couple of attributes i need to insert righjt now. i've collected the attributes in a dictionary. The other way round, to get all attributes is quite simple. But i fail to do it the other way round. Is there an easy was to insert the attributes from a dictionary to the tag? Unfortunately, the values can be a list as well as an attribute may have a tupel of entries:
Code:
<h1 class="class1 class2 class3">Header</h1>
i'm unable to find a function to insert the following dictionary
Code:
"{'class': ['invis','big'], 'id': 'page_i'}
into the tag so the result is
Code:
<h1 class="invis big" id='page_i'>Header</h1>
Hopefully there is a function in existence and i don't need to do it for myself
|\/|aui