An OG preview Python script can help developers inspect the Open Graph properties returned by a webpage. The basic workflow is to request the public HTML, parse its head and read values such as og:title, og:description, og:image and og:url. This is useful for debugging, batch QA and learning how social metadata works.
Install the Python packages
python -m pip install requests beautifulsoup4Fetch a public page and extract its OG tags
import requests
from bs4 import BeautifulSoup
OG_PROPERTIES = [
"og:title",
"og:description",
"og:type",
"og:url",
"og:image",
]
def inspect_open_graph(url: str) -> dict[str, str]:
response = requests.get(
url,
timeout=10,
headers={"User-Agent": "Mozilla/5.0 (compatible; MetadataInspector/1.0)"},
)
response.raise_for_status()
content_type = response.headers.get("Content-Type", "").lower()
if "text/html" not in content_type and "application/xhtml+xml" not in content_type:
raise ValueError(f"Expected HTML, received {content_type or 'unknown content type'}")
soup = BeautifulSoup(response.text, "html.parser")
result = {}
for prop in OG_PROPERTIES:
tag = soup.find("meta", attrs={"property": prop})
result[prop] = tag.get("content", "").strip() if tag else ""
return result
if __name__ == "__main__":
page = "https://example.com/article"
for key, value in inspect_open_graph(page).items():
print(f"{key}: {value or 'Not found'}")What this script does not prove
The script reads the HTML response returned to the Python client. It does not execute JavaScript, reproduce a social platform's crawler, validate image dimensions or clear any social cache. A platform may send a different user agent, receive different HTML or apply its own image and card rules. For JavaScript-rendered pages, use an authorised browser automation workflow and compare its result with the server source.
Add basic checks before trusting the output
- Confirm the HTTP status and response content type before parsing.
- Use a request timeout and impose a maximum response size for larger tools.
- Resolve relative image URLs against the page's final URL, then validate the image response separately.
- Check for duplicate OG properties instead of silently trusting the first value.
- If this script becomes a public service, block localhost, private/reserved IP addresses and unsafe redirects to prevent SSRF.
Use an online OG preview when you need a visual check
A short Python script is useful for extraction, but it does not show a social card. OpenGraph Preview combines public URL inspection, local HTML parsing, image validation, six simulated card layouts and copy-ready tag generation in one browser workflow.
Run a free Open Graph check online, or paste HTML into OpenGraph Preview when you are testing a page that is not public yet.
Open the free tool →