Question for you here, I\'m trying to add an attribute to a tag here, wondering if I can use a BeautifulSoup method, or should use plain string manipulation.
An exam
Easy with BeautifulSoup :)
>>> from bs4 import BeautifulSoup >>> soup = BeautifulSoup('BRITISH COLUMBIA') >>> soup.find('option')['selected'] = '' >>> print soup BRITISH COLUMBIA
The attributes can be looked at as a dictionary. So we have {'value':'BC'}, and to add a value to a dictionary, we just do dict[key] = value
{'value':'BC'}
dict[key] = value