socialmediaextractor
Find a website's social media profiles in one call, without picking up share buttons.
socialmediaextractor fetches a web page and returns the organization's profile links on
X/Twitter, LinkedIn, Instagram, Facebook, YouTube, TikTok, GitHub, Threads and Bluesky.
Why socialmediaextractor?
A plain "does the link contain twitter.com?" check also matches share buttons
(twitter.com/intent/tweet), single posts, embeds and look-alike domains. This library uses
per-platform URL rules instead, so you get account and profile URLs only.
Features
- Covers 9 platforms.
twitter.comandx.comare both reported underTwitter, andXis accepted as an alias. - Reads
<a href>,<link href>(for examplerel="me") and JSON-LDsameAsdeclarations. - Skips share, intent and dialog URLs, posts, reels, videos, embeds, GitHub issue pages, site-navigation pages and look-alike hosts.
- Resolves relative and protocol-relative (
//facebook.com/...) links. - Can return only the first link per platform or every distinct link (
extract_all_social_links). - Works on HTML you already have, so it fits into existing crawlers.
- Includes a
socialmediaextractorcommand, type hints (py.typed) and clear errors (SocialMediaExtractorError).
Installation
pip install socialmediaextractor
Requires Python 3.10+. Dependencies: requests and beautifulsoup4.
Quick start
from socialmediaextractor import extract_social_media_accounts
links = extract_social_media_accounts("https://www.djangoproject.com")
print(links)
Output (run on 2026-10-31):
{'Facebook': None,
'LinkedIn': 'https://www.linkedin.com/company/django-software-foundation',
'Twitter': 'https://x.com/djangoproject',
'Instagram': None,
'YouTube': None,
'TikTok': None,
'GitHub': 'https://github.com/django/django',
'Threads': None,
'Bluesky': 'https://bsky.app/profile/djangoproject.com'}
Every platform key is always present. Platforms with no link found are None.
Only some platforms
extract_social_media_accounts("https://example.com", platforms=["LinkedIn", "X"])
# {'LinkedIn': ..., 'Twitter': ...}
HTML you already fetched
from socialmediaextractor import extract_social_links_from_html, extract_all_social_links
first = extract_social_links_from_html(html, base_url="https://example.com/")
every = extract_all_social_links(html, base_url="https://example.com/") # dict[str, list[str]]
Classify a single URL
from socialmediaextractor import classify_url
classify_url("https://x.com/github") # 'Twitter'
classify_url("https://twitter.com/intent/tweet?text=hi") # None
Command line
socialmediaextractor https://www.python.org
socialmediaextractor https://www.mozilla.org --all -p Bluesky -p Instagram
socialmediaextractor site-a.com site-b.com # several URLs -> one JSON object keyed by URL
The command prints JSON to stdout and exits with code 1 if any URL fails.
Use cases
- Lead enrichment: add social profiles to a list of company domains.
- Brand monitoring: check which networks a competitor is active on.
- Data hygiene: confirm that your own site links to the right profiles.
- Crawlers: call
extract_social_links_from_htmlon pages you have already downloaded.
API overview
| Function | Returns |
|---|---|
extract_social_media_accounts(url, *, platforms=None, timeout=15.0, session=None) |
Fetches url; dict[str, str | None] with the first profile link per platform. |
extract_social_links_from_html(html, base_url=None, *, platforms=None) |
Same, from an HTML string. |
extract_all_social_links(html, base_url=None, *, platforms=None) |
dict[str, list[str]] with every distinct profile link. |
classify_url(url) |
Platform name or None. |
fetch_html(url, *, timeout=15.0, session=None) |
(html, final_url); raises SocialMediaExtractorError. |
PLATFORMS |
The Platform rules (name, hosts, path regex) used for matching. |
Upgrading from 0.x
from socialmediaextractor import extract_social_media_accountsworks again. The 0.2 to 0.4 wheels on PyPI shipped without any Python code, so the import failed.- The
Facebook,LinkedInandTwitterkeys are unchanged. Six new platform keys were added, andTwitternow also matchesx.com. - Share buttons and other non-profile links are no longer returned.
- Network and HTTP errors now raise
SocialMediaExtractorError. Before, an error page was silently parsed.
Contributing
Pull requests are welcome. See CONTRIBUTING.md.
pip install -e ".[dev]"
ruff check . && ruff format --check . && pytest
The tests run offline against saved HTML fixtures in tests/fixtures/. To add a platform, add a
Platform entry in socialmediaextractor/extractor.py along with fixture cases.
License
MIT. See LICENSE.
Metadata
Release files for socialmediaextractor 1.0.0
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 |
|---|---|---|---|---|
| socialmediaextractor-1.0.0.tar.gz | 16.1 kB | Without provenance | Details for socialmediaextractor-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| socialmediaextractor-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for socialmediaextractor-1.0.0-py3-none-any.whl |
Total release size: 26.8 kB
Security for socialmediaextractor 1.0.0
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.
Release files / socialmediaextractor-1.0.0.tar.gz
How to use checksums
c744b70b71f59ffd40ded0eaebe0178125506493211b8b5a0c023552c58e7187How to use checksums
13cc30fe1977b962a293a82f3a16ecb4bdb7baee5b40a96914f98cd7f39bf1a1What is trusted publishing?
twine/7.0.0 CPython/3.11.7