“Récupérer le contenu à l'intérieur du méta tag python” Réponses codées

Récupérer le contenu à l'intérieur du méta 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")
bharath

Récupérer le contenu à l'intérieur du méta tag python

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#importing the libraries
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
# the hard part that doesn't work - I know this example is well off the mark!        
    title = soup.find("og:title", "content")
    print (title.get_text())
    url = soup.find("og:url", "content")
    print (url.get_text())
# end of problem

for i in range (1,100):
    get_data(i)
bharath

Récupérer le contenu à l'intérieur du méta 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)
bharath

Réponses similaires à “Récupérer le contenu à l'intérieur du méta tag python”

Questions similaires à “Récupérer le contenu à l'intérieur du méta tag python”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code