Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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")
Comment

retrieve content inside the meta 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)
Comment

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)
Comment

PREVIOUS NEXT
Code Example
Python :: Amazing Trees with python turtle 
Python :: The function to be built, amino_acids, must return a list of a tuple and an integer when given a string of mRNA code. 
Python :: keras functional api embedding layer 
Python :: python code to increase cpu utilization 
Python :: read excel by row and output to txt 
Python :: add text to jpg python 
Python :: remove SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame 
Python :: print f python 
Python :: numpy replace all values with another 
Python :: Getting the first element from each list in a column of lists 
Python :: Django Redirect Depending On Request Method 
Python :: choice without replacement python 
Python :: unique list 
Python :: python combinations function 
Python :: change group box border color pyqt5 
Python :: seaborn heatmap center xticks 
Python :: python plot n numbers from normal distribution 
Python :: scale values in 0 100 python 
Python :: get script text selenium python 
Python :: turtle screen 
Python :: Python colon equals 
Python :: find in python 
Python :: python reading into a text file and diplaying items in a user friendly manner 
Python :: Finding Maximum Elements along columns using Python numpy.argmax() 
Python :: pandas convert hex string to int 
Python :: python regex find single character 
Python :: numpy primes 
Python :: python set terminal size 
Python :: python append to tuple list 
Python :: odoo manifest 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =