Skip to main content

Grab OpenGraph and Twitter Cards metadata from URL and HTML documents

Project description

Tweesky

Tweesky is a Python library for extracting HTML, OpenGraph and Twitter metadata from URLs, HTML pages and Spotify links.

How to use it

Grab attributes from a URL

    website = 'https://www.nike.com/'
    card = generate_card(url=website)
    
    print(card.title)
    print(card.image)

Grab attributes from an HTML document

    with open('doc.html', 'r') as reader:
        doc = reader.readlines()
    card = generate_card(html=doc)
    
    print(card.title)
    print(card.image)

Output options

There are different options to format the card:

  • Card object (default): access the Python object to obtain the metadata
  • JSON output: the Card content is provided as JSON
  • HTML file: an HTML file is provided including the metadata necessary for creating the Social Media preview

HTML format

When using main.generate_card_as_html() method the output is an HTML document which can be shared as-is on Social Media.

The HTML document provides all necessary OpenGraph/Twitter tags as well as the Javascript code to redirect the users to the original page: save the file on an accessible location and distribute the link through the Social Media channels.

<html>
    <head>
        <meta name="twitter:card" content="summary" />
        <meta name="twitter:title" content="Python Tutorials – Real Python" />
        <meta name="twitter:description" content="Learn Python online" />
        <meta name="twitter:image" content="https://cdn.realpython.com/static/logo.png" />
        <meta name="twitter:site" content="@realpython" />
        
        <meta property="og:title" content="Python Tutorials – Real Python" />
        <meta property="og:description" content="Learn Python online" />
        <meta property="og:image" content="https://cdn.realpython.com/static/logo.png" />
        
        <meta http-equiv="refresh" content="0; url=https://realpython.com/" /> 
    </head>
    <body >
        &nbsp;
    </body>
</html>  

Images

When finding the image for the Preview the library will search the following:

  • Twitter Card metadata
  • OpenGraph metadata
  • JSON LD

When no image is found WebDriver can be used to take a screenshot.

In that case configure WebDriver settings accordingly:

# path to driver
WEBDRIVER_PATH=/webdriver/chromedriver
# local or remote WebDriver
WEBDRIVER_TYPE=local
# path to screenshot files
SCREENSHOTS_LOCATION=/tmp

More Info

To find out more:

Project details


Download files

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

Source Distribution

tweesky-0.0.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tweesky-0.0.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file tweesky-0.0.2.tar.gz.

File metadata

  • Download URL: tweesky-0.0.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for tweesky-0.0.2.tar.gz
Algorithm Hash digest
SHA256 409826def49192b557a3aaf7992b628663adf3169c5e17270b466b147052ebd3
MD5 43fa6584135e1e65de6f8082f3716372
BLAKE2b-256 70d68778ae2d38fc3e521db4319cd75d897447deab3d629bf0c515b0aa9cdc2d

See more details on using hashes here.

File details

Details for the file tweesky-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: tweesky-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for tweesky-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f042976fd980da07d4ec010f1216c431ca65796f21e4c6bc2b4d73e190fcb37
MD5 257942bbe001707e581a9f3227acfb9c
BLAKE2b-256 fe228a5647f6750fbddc7a187fb60e33805da07572100933954ed43c9d5607cb

See more details on using hashes here.

Supported by

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