retrieve all meta tags python beautifulsoup code example
Example 1: retrieve content inside the meta tag python
title = soup.find("meta", property="og:title")
url = soup.find("meta", property="og:url")
print(title["content"] if title else "No meta title given")
print(url["content"] if url else "No meta url given")
Example 2: retrieve content inside the meta tag python
from urllib import urlopen
from bs4 import BeautifulSoup
def get_data(page_no):
webpage = urlopen('http://superfunevents.com/?p=' + str(i)).read()
soup = BeautifulSoup(webpage, "lxml")
for tag in soup.find_all("article") :
id = tag.get('id')
print id
title = soup.find("og:title", "content")
print (title.get_text())
url = soup.find("og:url", "content")
print (url.get_text())
for i in range (1,100):
get_data(i)
Example 3: retrieve content inside the meta tag python
soup = BeautifulSoup(webpage)
for tag in soup.find_all("meta"):
if tag.get("property", None) == "og:title":
print tag.get("content", None)
elif tag.get("property", None) == "og:url":
print tag.get("content", None)