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 >
</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:
- Tweesky Web Site: example of what Tweesky can do
- Intro on Medium: Tweesky: don’t miss the Twitter Card preview
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
Built Distribution
File details
Details for the file tweesky-0.0.1.tar.gz
.
File metadata
- Download URL: tweesky-0.0.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ed601f68ebc40be59a933e0ef2e0f57392658b1a5a89e6e9d6056f9c408f0ef |
|
MD5 | 664c81e829d455d47de5aed6a9d8a0e6 |
|
BLAKE2b-256 | 83cf4166cace64a4e6f4606d000a08fb91926c0f6f66df5ab3b2f59872f10e77 |
File details
Details for the file tweesky-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: tweesky-0.0.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca8940b141f9337ba6f82882d203e3b45940c005db402b2037c355adb27010fb |
|
MD5 | a24b9fef181b0c8f2fa16f3689841e7c |
|
BLAKE2b-256 | b2234f5a4608d87efe2fc52f151aa075af9c6b0097757fd9a8e2c2a5a88c8f19 |