# i`m look meta, but if :
price = soup.find(name="twitter:label1")
That’s because name
is already a parameter key name of the function (https://bazaar.launchpad.net/~leonardr/beautifulsoup/bs4/view/head:/bs4/element.py#L1871), so it won’t be recognized as an attribute name. If you wanted to search the attribute name, you’ll have to do it this way so it doesn’t conflict:
>>> soup.find(attrs={'name': 'twitter:label1'})
<meta content="3046 UAH" name="twitter:label1"/>
While it’s easier to type name="twitter:label1"
, I’ve personally always found this approach awkward because not all names can be specified, whether it’s class
that must be done as _class
or things like name
which cannot be used at all. Using attrs
gives you a reliable way to always get the attributes.
An alternative is to use CSS selectors:
>>> soup.select_one('meta[name="twitter:label1"]')
<meta content="3046 UAH" name="twitter:label1"/>