Skip to main content

socialmediaextractor

Find a website's social media profiles in one call, without picking up share buttons.

PyPI Python Tests Downloads License: MIT Ruff

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.com and x.com are both reported under Twitter, and X is accepted as an alias.
  • Reads <a href>, <link href> (for example rel="me") and JSON-LD sameAs declarations.
  • 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 socialmediaextractor command, 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_html on 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_accounts works again. The 0.2 to 0.4 wheels on PyPI shipped without any Python code, so the import failed.
  • The Facebook, LinkedIn and Twitter keys are unchanged. Six new platform keys were added, and Twitter now also matches x.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)

Source distribution for socialmediaextractor 1.0.0
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)

Table of built distributions (wheels) for socialmediaextractor 1.0.0
File Interpreter ABI Platform Actions
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

Release files / socialmediaextractor-1.0.0.tar.gz

Download URL socialmediaextractor-1.0.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c744b70b71f59ffd40ded0eaebe0178125506493211b8b5a0c023552c58e7187
BLAKE2b-256 checksum
How to use checksums
13cc30fe1977b962a293a82f3a16ecb4bdb7baee5b40a96914f98cd7f39bf1a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.7

Release files / socialmediaextractor-1.0.0-py3-none-any.whl

Download URL socialmediaextractor-1.0.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4ba983dded0467638629d5bb0fe6dd0c4e206350df7250db7209f1af403584d
BLAKE2b-256 checksum
How to use checksums
2aefb219a428a998d80806aa10a40daa5d01c93e08cc45ff143214e163d6f966
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.7

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page