https://github.com/erikriver/opengraph
A python module to parse the Open Graph Protocol
https://github.com/erikriver/opengraph
ogp python
Last synced: 5 months ago
JSON representation
A python module to parse the Open Graph Protocol
- Host: GitHub
- URL: https://github.com/erikriver/opengraph
- Owner: erikriver
- License: mit
- Created: 2011-06-17T08:11:10.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2021-12-26T03:18:57.000Z (almost 4 years ago)
- Last Synced: 2024-11-11T11:12:01.309Z (about 1 year ago)
- Topics: ogp, python
- Language: Python
- Homepage: http://ogp.me/
- Size: 14.6 KB
- Stars: 228
- Watchers: 15
- Forks: 82
- Open Issues: 23
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-python-cn - opengraph
- awesome-python - opengraph - A Python module to parse the Open Graph Protocol (Web Content Extracting)
- fucking_awesome_python - opengraph - A Python module to parse the Open Graph Protocol (Web Content Extracting)
- awesome-python - opengraph - A Python module to parse the Open Graph Protocol (Web Content Extracting)
- awesome-python-cn - opengraph
- Python-Awesome - opengraph - A Python module to parse the Open Graph Protocol (Web Content Extracting)
README
OpenGraph is a module of python for parsing the Open Graph Protocol, you can read more about the specification at http://ogp.me/
Installation
=============
.. code-block:: console
$ pip install opengraph
Features
=============
* Use it as a python dict
* Input and parsing from a specific url
* Input and parsung from html previous extracted
* HTML output
* JSON output
Usage
==============
**From an URL**
.. code-block:: pycon
>>> import opengraph
>>> video = opengraph.OpenGraph(url="http://www.youtube.com/watch?v=q3ixBmDzylQ")
>>> video.is_valid()
True
>>> for x,y in video.items():
... print "%-15s => %s" % (x, y)
...
site_name => YouTube
description => Eric Clapton and Paul McCartney perform George Harrison's "While My Guitar Gently Weeps" at the...
title => While My Guitar Gently Weeps
url => http://www.youtube.com/watch?v=q3ixBmDzylQ
image => http://i2.ytimg.com/vi/q3ixBmDzylQ/default.jpg
video:type => application/x-shockwave-flash
video:height => 224
video => http://www.youtube.com/v/q3ixBmDzylQ?version=3&autohide=1
video:width => 398
type => video
**From HTML**
.. code-block:: pycon
>>> HTML = """
...
...
... The Rock (1996)
...
...
...
...
...
...
... """
>>> movie = opengraph.OpenGraph() # or you can instantiate as follows: opengraph.OpenGraph(html=HTML)
>>> movie.parser(HTML)
>>> video.is_valid()
True
**Generate JSON or HTML**
.. code-block:: pycon
>>> ogp = opengraph.OpenGraph("http://ogp.me/")
>>> print ogp.to_json()
{"image:type": "image/png", "title": "Open Graph protocol", "url": "http://ogp.me/", "image": "http://ogp.me/logo.png", "scrape": false, "_url": "http://ogp.me/", "image:height": "300", "type": "website", "image:width": "300", "description": "The Open Graph protocol enables any web page to become a rich object in a social graph."}
>>> print ogp.to_html()