Get link (URL) preview
Project description
linkpreview
Get link preview in python
Gathering data from:
- OpenGraph meta tags
- TwitterCard meta tags
- Schema.org meta tags
- HTML Generic tags (
h1
,p
,img
) - URL readable parts
Install
pip install linkpreview
Usage
Basic:
from linkpreview 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)
Automatic fetch link content
from linkpreview 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)
Use lxml
as XML parser:
Very recommended for better performance
from linkpreview 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)
Advanced
from linkpreview import Link, LinkPreview, LinkGrabber
url = "http://github.com"
grabber = LinkGrabber(
initial_timeout=20, maxsize=1048576, receive_timeout=10, chunk_size=1024,
)
content = 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
linkpreview-0.1.12.tar.gz
(5.0 kB
view details)
File details
Details for the file linkpreview-0.1.12.tar.gz
.
File metadata
- Download URL: linkpreview-0.1.12.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc13e87f33da4911fb581ec38ca2100d55188ad128975489bd33a167328ad5b4 |
|
MD5 | 981982218cfd2deac22b29d9fe79e7cd |
|
BLAKE2b-256 | 2decad3410eb7fd368aefa58a70736089faeb2d54ab4e1d07899b2b2a2680ddb |