retrieve content inside the meta tag python

Solutions on MaxInterview for retrieve content inside the meta tag python by the best coders in the world

showing results for - "retrieve content inside the meta tag python"
Matisse
15 Jun 2016
1title = soup.find("meta",  property="og:title")
2url = soup.find("meta",  property="og:url")
3
4print(title["content"] if title else "No meta title given")
5print(url["content"] if url else "No meta url given")
6
Erica
10 Sep 2017
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#importing the libraries
5from urllib import urlopen
6from bs4 import BeautifulSoup
7
8def get_data(page_no):
9    webpage = urlopen('http://superfunevents.com/?p=' + str(i)).read()
10    soup = BeautifulSoup(webpage, "lxml")
11    for tag in soup.find_all("article") :
12        id = tag.get('id')
13        print id
14# the hard part that doesn't work - I know this example is well off the mark!        
15    title = soup.find("og:title", "content")
16    print (title.get_text())
17    url = soup.find("og:url", "content")
18    print (url.get_text())
19# end of problem
20
21for i in range (1,100):
22    get_data(i)
23
Erica
24 Nov 2019
1soup = BeautifulSoup(webpage)
2for tag in soup.find_all("meta"):
3    if tag.get("property", None) == "og:title":
4        print tag.get("content", None)
5    elif tag.get("property", None) == "og:url":
6        print tag.get("content", None)
7