Unfurl.Net
1.1.0
dotnet add package Unfurl.Net --version 1.1.0
NuGet\Install-Package Unfurl.Net -Version 1.1.0
<PackageReference Include="Unfurl.Net" Version="1.1.0" />
paket add Unfurl.Net --version 1.1.0
#r "nuget: Unfurl.Net, 1.1.0"
// Install Unfurl.Net as a Cake Addin #addin nuget:?package=Unfurl.Net&version=1.1.0 // Install Unfurl.Net as a Cake Tool #tool nuget:?package=Unfurl.Net&version=1.1.0
Unfurl.Net
A .net metadata scraper that supports X (nee Twitter) Cards, Open Graph, and oEmbed.
Installation
Unfurl.Net is published as a NuGet package. Download from your favorite nuget package manager.
--or--
Install from the command line with:
dotnet add package Unfurl.Net
Overview
Unfurl.Net is inspired by the unfurl.js nodejs project which parses meta data from HTML content and turns it into a convenient object model for displaying URL previews and cards similar to how Facebook, Slack, Discord, or Twitter do.
This library just parses the Html for OpenGraph and Twitter Card <meta />
tags and turns it into an easy to use object. It does not actually build a visual representation of the Url.
Unfurl.Net is a simple library that depends on the venerable HtmlAgilityPack for its parsing.
Usage
Basic usage that loads open graph and X/Twitter cards:
var unfurler = new Unfurler();
var url = "https://developer.x.com/en/docs/x-for-websites/cards/overview/markup";
var results = await unfurler.Unfurl(url);
Include oEmbed data:
var httpClient = new HttpClient(); // <-- don't do this in production!
var unfurler = new Unfurler();
var url = "https://www.youtube.com/watch?v=5EI0OP7o8cM";
var results = await unfurler.Unfurl(url, new UnfurlOptions()
{
LoadOEmbed = true,
OEmbedHttpClient = httpClient,
});
Handle redirects and shortened links:
var unfurler = new Unfurler();
var url = "https://www.youtube.com/watch?v=5EI0OP7o8cM";
var results = await unfurler.Unfurl(url, new UnfurlOptions()
{
MaximumRedirects = 2,
});
All Options:
Property | Description |
---|---|
Encoding | set the encoding of the target url. Default to null |
Credentials | pass in custom network credentials if needed. |
CancellationToken | control cancellation of the network requests |
MaximumRedirects | the number of redirects to follow from 301 or 302 responses. |
UserAgent | the user-agent string to pass as part of the request headers. Defaults to "Unfurl.Net/1.1" |
LoadOEmbed | whether or not to make the extra web-request to load any oEmbed content |
OEmbedHttpClient | Instance of HttpClient to use for querying oEmbed. If null, will create a new instance of HttpClient which has performance implications for high-volume services. |
Roadmap
The current features are sufficient for my needs. But if there are any additional features you would like to see, please add an issue (or even submit a PR if you want) and I will work on adding them.
Here are some features that could be added:
- Accept Html as a string or stream for parsing, and not just a Url that has to be downloaded. This will allow alternate methods of downloading Urls and Unfurl.Net can be used simply as the parser, not also as the Html downloader.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- HtmlAgilityPack (>= 1.11.57)
- Microsoft.AspNet.WebApi.Client (>= 6.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.