0

Actually I want to scrape the " content " attribute from the below html code:

<meta name="description" content="Definition: What is a leadership performer?"/>

I want to scrape "Definition: What is a leadership performer?" from the above code but I do not know how to do that.

Can anyone guide me?

Here's my code, not working and I can't get what I stated above!

from bs4 import BeautifulSoup
import requests
import time
import pandas


    
r=requests.get('https://neculaifantanaru.com/en/definition-what-is-a-performer.html')
#print(r.text)

soup=BeautifulSoup(r.text, 'html.parser')


var2=soup.find_all('meta', attrs={'content':"Definition: What is a leadership performer?"})
for z in var2:
    print(z.text.strip())
  • Does this answer your question? [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) – MendelG May 26 '21 at 21:34

2 Answers2

0

You could do something like this:

soup.find("meta", {'name' : "description"})["content"]
joni
  • 6,840
  • 2
  • 13
  • 20
0

I found the way to do that, this is how I did it.

for tag in soup.find_all("meta"):
if tag.get("name", None) == "description":
    print(tag.get("content", None))