Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data from the meta tags using BeautifulSoup

I am trying to read the description from the meta tag and this is what I used

soup.findAll(name="description")

but it does not work, however, the code below works just fine

soup.findAll(align="center")

How do I read the description from the meta tag in the head of a document?

like image 976
iJK Avatar asked Sep 23 '10 00:09

iJK


People also ask

How do you scrape a tag with BeautifulSoup?

Step-by-step Approach. Step 1: The first step will be for scraping we need to import beautifulsoup module and get the request of the website we need to import the requests module. Step 2: The second step will be to request the URL call get method.


1 Answers

Yep, name can't be used in keyword-argument form to designate an attribute named name because the name name is already used by BeautifulSoup itself. So use instead:

soup.findAll(attrs={"name":"description"})

That's what the attrs argument is for: passing as a dict those attribute constraints for which you can't use keyword-argument form because their names are Python keyword or otherwise taken by BeautifulSoup itself!

like image 180
Alex Martelli Avatar answered Sep 18 '22 16:09

Alex Martelli