Meta Data Parser
unfurl
Unfurling is the process of extracting metadata from a webpage, such as its title, description, and main image.
The simple unfurl
method of the sdk takes either an array of URLs or a single URL and returns a standardized object of metadata.
Arguments:
Argument | Type | Description |
---|---|---|
urls | string , string[] - required | A URL, as a string, or an array of strings |
Return Value
When given an array of URL, the unfurl method returns an objects where each key is a submitted URL and the value represents the metadata of that URL. When given a string URL, the unfurl method returns an object representing the metadata of that URL. In both cases, the metadata object has the following properties:
Different webpages publish different sets of metadata. The object returned will have some subset of the following properties, based on the available metadata for the URL.
title
: The title of the webpage.description
: The description of the webpage.url
: The original URL.canonical_url
: The canonical URL of the page.images
: an array of objects, each representing an image with at a minimum aurl
property. Theurl
property is the URL of the image. The other properties are optional and arealt
text,secure_url
link and thewidth
andheight
of the image.icon
: A link to the favicon of the webpage.site_name
: The name of the website.type
: The type of the webpage. This is usuallywebsite
orarticle
.locale
: The locale of the webpage.
Please note that not all websites allow parsing of their metadata, and the results of the unfurl
method are not 100% guaranteed. In some cases, websites may block parsing or provide incomplete or incorrect metadata. Additionally, be mindful of the website's terms of service and any applicable laws or regulations related to web scraping.
Examples
- Single URL
- Multiple URLs
Usage
const metadata = await window.wyng['_WYNG_ID_'].unfurl('https://www.example.com/blog');
console.log(metadata);
Result
{
"title": "Example Domain",
"description": "This is a very real website description.",
"url": "https://www.example.com/blog",
"canonical_url": "https://blog.example.com",
"images": [
{
"url": "https://www.example.com/images/thumbnail.png",
"alt": "Example thumbnail",
"width": 400,
"height": 200
}
],
"icon": "https://www.example.com/favicon.ico",
"site_name": "Example",
"type": "website",
"locale": "en_US"
}
const urls = [
'https://www.example.com/',
'https://www.example.com/good_car_ideas',
'https://www.example.com/product/dan_flashes/shirt_pattern_UCSD2356',
];
const metadata = await window.wyng['_WYNG_ID_'].unfurl(urls);
console.log(metadata);
Result
{
"https://www.example.com/": {
"title": "Example Domain",
"description": "Just another example website. Nothing to see here.",
"url": "https://www.example.com/",
"images": [
{
"url": "https://www.example.com/images/thumbnail.png",
"alt": "Example thumbnail",
"width": 800,
"height": 600
}
],
"icon": "https://www.example.com/favicon.ico",
"site_name": "Example",
"type": "website",
"locale": "en_US"
},
"https://www.example.com/blog/good_car_ideas": {
"title": "Good Car Ideas",
"description": "Idea 1: A good steering wheel, that doesn't fly out of the window while I'm driving.",
"url": "https://www.example.com/blog/good_car_ideas",
"canonical_url": "https://blog.example.com/good_car_ideas",
"images": [
{
"secure_url": "https://www.example.com/images/article_cover.png",
"url": "https://www.example.com/images/article_cover.png",
"alt": "Photo of a car with no steering wheel, I'm toast.",
"width": 800,
"height": 600
}
],
"icon": "https://www.example.com/favicon.ico",
"site_name": "Example",
"type": "article",
"locale": "en_US"
},
"https://www.example.com/product/dan_flashes/shirt_pattern_UCSD2356": {
"title": "Dan Flashes Shirt Pattern UCSD2356 - Limited Edition",
"description": "Our most complicated shirt yet, that's why it's $2000",
"url": "https://www.example.com/product/dan_flashes/shirt_pattern_UCSD2356",
"images": [
{
"url": "https://www.example.com/images/shirts/UCSD2356.jpg",
},
{
"url": "https://www.example.com/images/shirts/UCSD2356-2.jpg",
"secure_url": "https://www.example.com/images/shirts/UCSD2356-2.jpg",
}
],
"icon": "https://www.example.com/favicon.ico",
"site_name": "Example",
"type": "product",
"locale": "en_US"
}
}