View Single Post
Old 04-03-2018, 06:00 AM   #402
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,738
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Maui View Post
Is there an easy was to insert the attributes from a dictionary to the tag?
bs4 uses the default dictionary syntax for tag attributes.
E.g., you'd use the following code to add attributes:

Code:
new_tag = soup.new_tag('h1')
new_tag['class'] = 'invis big'
new_tag['id'] = 'page_i'
you could also manipulate the attrs property:

Code:
new_tag = soup.new_tag('h1')
new_tag.attrs = {'class': 'invis big', 'id': 'page_i'}

Last edited by Doitsu; 04-03-2018 at 06:14 AM.
Doitsu is offline   Reply With Quote