dotancohen
dotancohen

Reputation: 31511

Access the 'content' attribute of the 'description' meta tag

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

Answers (1)

Mezgrman
Mezgrman

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

Related Questions