linkpreview
Get link preview in python
Gathering data from:
- OpenGraph meta tags
- TwitterCard meta tags
- Microdata meta tags
- JSON-LD meta tags
- HTML Generic tags (
h1,p,img) - URL readable parts
Install
pip install linkpreview
Usage
Basic
from previewlink_helper import link_preview
url = "http://localhost"
content = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<!-- ... --->
<title>a title</title>
</head>
<body>
<!-- ... --->
</body>
</html>
"""
preview = link_preview(url, content)
print("title:", preview.title)
print("description:", preview.description)
print("image:", preview.image)
print("force_title:", preview.force_title)
print("absolute_image:", preview.absolute_image)
print("site_name:", preview.site_name)
print("favicon:", preview.favicon)
print("absolute_favicon:", preview.absolute_favicon)
Automatic fetch link content
from previewlink_helper import link_preview
preview = link_preview("http://github.com/")
print("title:", preview.title)
print("description:", preview.description)
print("image:", preview.image)
print("force_title:", preview.force_title)
print("absolute_image:", preview.absolute_image)
print("site_name:", preview.site_name)
print("favicon:", preview.favicon)
print("absolute_favicon:", preview.absolute_favicon)
lxml as XML parser
Very recommended for better performance.
Install the lxml and use it like this:
from previewlink_helper import link_preview
preview = link_preview("http://github.com/", parser="lxml")
print("title:", preview.title)
print("description:", preview.description)
print("image:", preview.image)
print("force_title:", preview.force_title)
print("absolute_image:", preview.absolute_image)
print("site_name:", preview.site_name)
print("favicon:", preview.favicon)
print("absolute_favicon:", preview.absolute_favicon)
Advanced
from previewlink_helper import Link, LinkPreview, LinkGrabber
url = "http://github.com"
grabber = LinkGrabber(
initial_timeout=20,
maxsize=1048576,
receive_timeout=10,
chunk_size=1024,
)
content, url = grabber.get_content(url)
link = Link(url, content)
preview = LinkPreview(link, parser="lxml")
print("title:", preview.title)
print("description:", preview.description)
print("image:", preview.image)
print("force_title:", preview.force_title)
print("absolute_image:", preview.absolute_image)
print("site_name:", preview.site_name)
print("favicon:", preview.favicon)
print("absolute_favicon:", preview.absolute_favicon)
Metadata
Release files for previewlink-helper 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| previewlink_helper-0.0.3.tar.gz | 14.3 kB | Without provenance | Details for previewlink_helper-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| previewlink_helper-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for previewlink_helper-0.0.3-py3-none-any.whl |
Total release size: 26.4 kB
Release files / previewlink_helper-0.0.3.tar.gz
| Download URL | previewlink_helper-0.0.3.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22d618dfca8788e09f34ac99be95760aba911c0413770aee48e308249ac534ea
|
|
BLAKE2b-256 checksum How to use checksums |
46f95c344d6a59573f4416279ae5154e0272d5665ae9171d241556ad2d7b63da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / previewlink_helper-0.0.3-py3-none-any.whl
| Download URL | previewlink_helper-0.0.3-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8b8356408176c6b2934690d123f2bf5bf0e0069dfe1d3ae5ab81112545f79ca
|
|
BLAKE2b-256 checksum How to use checksums |
88fbd68f18f73cf3b1ac510c4cab0b351b874657fa49b52804332aa7c6c031f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for previewlink-helper 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.