How do I get the second reference during the for loop iteration in the below program in Beautiful Soup

13 views
Skip to first unread message

john kurian

unread,
Jun 14, 2017, 7:07:42 AM6/14/17
to beautifulsoup
Hello Guys, 

I am very new to Python and wanted to scrape a webpage using BeautifulSoup. 

In the below program when I use the for loop i.e.{ for m in soup.find_all('meta'):}, I get the data / text in all the meta tags

However, I am only interested in the data which is present in the second meta tab - i.e. (Python Programming tutorials from beginner to advanced on a massive variety of topics. All video and text tutorials are free)

Is there anyway I can pull out only the data in the second meta tab and not the others?

Please find the code below for your reference


import bs4 as bs
import urllib.request
import re

soup = bs.BeautifulSoup(sauce, 'lxml')


for m in soup.find_all('meta'):
    #print(m.get('content'))
    a = m.get('content')
    print(a)
Reply all
Reply to author
Forward
0 new messages