Skip to main content

Extracts OpenGraph, TwitterCard and Schema properties from a webpage.

Project description

# About
Webpreview helps preview a webpage. It extracts [Open Graph](http://ogp.me/), [Twitter Card](https://dev.twitter.com/cards/overview) and [Schema](http://schema.org/) meta tags. Given a URL of a page, it extracts title, thumbnail, description, etc as per request.

#Installation

$ pip install webpreview

#Usage
## Preview a Web Page
API: `web_preview(url, timeout?, headers?)`

Use `web_preview` for extracting title, description and thumbnail image. It tries to extract them from Open Graph properties, if not found it falls back to Twitter Card, and so on till Schema. If non works it tries to extract from the webpage's content.

$ from webpreview import web_preview
$ title, description, image = web_preview("aurl.com")

# specifing timeout which gets passed to requests.get()
$ title, description, image = web_preview("a_slow_url.com", timeout=1000)

# passing headers
$ headers = {'User-Agent': 'Mozilla/5.0'}
$ title, description, image = web_preview("a_slow_url.com", headers=headers)

## Open Graph
API: `OpenGraph(url, properties, timeout?, headers?)`

`OpenGraph` extracts Open Graph meta properties. Consider following meta tags.

<!--doc snippet at aurl.com -->
<meta property="og:title" content="a title" />
<meta property="og:description" content="a description" />
<meta property="article:published_time" content="2013-09-17T05:59:00+01:00" />
<meta property="og:price:amount" content="15.00" />

Below is a snippet showing its usage.

$ from webpreview import OpenGraph

# pass a URL and a list of meta properties
$ og = OpenGraph("http://aurl.com", ["og:title", "article:published_time", "og:price:amount"])

# OpenGraph dynamically assigns corresponding properties to its instance. As you will see it excludes `og:` from the supplied properties.
$ og.title
=> "a title"
$ og.published_time
=> "2013-09-17T05:59:00+01:00"

# It converts `:` in a property into `_`.
$ og.price_amount
=> "15.00"

## Twitter Card
API: `TwitterCard(url, properties, timeout?, headers?)`

`TwitterCard` extracts Twitter Card meta properties from the given webpage. Its usage is similar to `OpenGraph`.

$ from webpreview import TwitterCard
$ tc = TwitterCard("aurl.com", ["twitter:title", "twitter:image"])
$ tc.title
$ tc.image

## Schema
API: `Schema(url, properties, timeout?, headers?)`

Webpreview supports Schema through the class `Schema`. Right now it extracts properties in meta tags only.

$ from webpreview import Schema
$ aschema = Schema("aurl.com", ["name", "camelCaseProperty"]
$ aschema.name
# It makes Camel Case properties available as Snake Case.
$ aschema.camel_case_property

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

webpreview-1.3.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file webpreview-1.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for webpreview-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d501c2c8dfb98ed0a6d31239dc3573080b3a9a443bbac1db7ec7bda66e1373d
MD5 220a400ced7ae6a0ff380be02cfce28d
BLAKE2b-256 d81dffc96d0ed74aeb182a87ce5f546449ff860918e73740aef2745951e89939

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page