Reputation: 31511
When using Beautiful Soup to access a meta tag the result is presented as the entire tag:
soup.find(attrs={"name":"description"})
<meta content="If youre looking for Dotan Cohen, here I am." name="description"/>
How might one parse that result to get only the content of the content
attribute?
Upvotes: 0
Views: 360
Reputation: 886
According to the documentation, .find()
returns an object whose keys you can access.
Try:
tag = soup.find(attrs={"name":"description"})
content = tag['content']
Note that this returns only the first matching tag. If you need all matching tags, use .findall()
, which returns a list of tags.
Upvotes: 2