X.Web.MetaExtractor
3.0.0
Prefix Reserved
dotnet add package X.Web.MetaExtractor --version 3.0.0
NuGet\Install-Package X.Web.MetaExtractor -Version 3.0.0
<PackageReference Include="X.Web.MetaExtractor" Version="3.0.0" />
<PackageVersion Include="X.Web.MetaExtractor" Version="3.0.0" />
<PackageReference Include="X.Web.MetaExtractor" />
paket add X.Web.MetaExtractor --version 3.0.0
#r "nuget: X.Web.MetaExtractor, 3.0.0"
#:package X.Web.MetaExtractor@3.0.0
#addin nuget:?package=X.Web.MetaExtractor&version=3.0.0
#tool nuget:?package=X.Web.MetaExtractor&version=3.0.0
X.Web.MetaExtractor
X.Web.MetaExtractor is a powerful library that allows you to extract meta information from any web page URL. It provides a variety of content loaders to handle HTTP requests using different libraries.
Breaking Changes
3.0
- Content loader packages are discontinued:
X.Web.MetaExtractor.ContentLoaders.Flurl,X.Web.MetaExtractor.ContentLoaders.FsHttpandX.Web.MetaExtractor.ContentLoaders.RestSharpare no longer published. Use the built-inHttpClientContentLoaderor implementIContentLoaderyourself (see Custom Content Loader). - Target frameworks: the package now targets
net8.0andnet10.0. HttpClientFactoryno longer shares clients between instances: keep one instance for the lifetime of the application, or useAddMetaExtractor()with dependency injection.
2.x
- Metadata class was changed: The
Contentfield has been removed from theMetadataclass. Ensure to update your code to reflect this change if you were using theContentfield. - Description Extraction Logic: The
Extractorclass now only extracts the description from meta tags, without attempting to parse the content of the page. - New WebPage Model: The library now returns a
WebPagemodel with comprehensive information including links found on the page. - Link Extraction: Added support for extracting and processing all hyperlinks from web pages.
Features
- Extract meta information from any web page URL.
- Extract and process hyperlinks from web pages.
- Built-in
HttpClient-based content loader with configurable timeout and User-Agent. - Dependency injection support via
services.AddMetaExtractor(). - Pluggable content loading through
IContentLoader. - Detect the language of the page content.
Installation
To install the library, use the following command:
dotnet add package X.Web.MetaExtractor
Usage
Here is a basic example of how to use the X.Web.MetaExtractor library:
using X.Web.MetaExtractor;
IExtractor extractor = new Extractor("https://example.com/example.jpg");
// Extract information from a URL
var webPage = await extractor.Extract(new Uri("https://example.com"), CancellationToken.None);
// Display the extracted information
Console.WriteLine($"Title: {webPage.Title}");
Console.WriteLine($"Description: {webPage.Description}");
Console.WriteLine($"Keywords: {string.Join(", ", webPage.Keywords)}");
Console.WriteLine($"Language: {webPage.Language}");
// Process links
Console.WriteLine($"Found {webPage.Links.Count} links:");
foreach (var link in webPage.Links)
{
Console.WriteLine($"- {link.Title}: {link.Value}");
}
Dependency Injection
builder.Services.AddMetaExtractor(options =>
{
options.DefaultImage = "https://example.com/example.jpg";
options.MaxDescriptionLength = 500;
options.ContentLoader.Timeout = TimeSpan.FromSeconds(10);
options.ContentLoader.UserAgent = "MyApp/1.0";
});
// Then inject IExtractor wherever you need it
public class PreviewService(IExtractor extractor) { ... }
AddMetaExtractor() registers a named client through IHttpClientFactory, so connection pooling and DNS refresh are handled by .NET. To use your own loader, register IContentLoader before calling AddMetaExtractor().
Interfaces and Classes
IExtractor
IExtractor defines the interface for extracting web page information, returning a comprehensive WebPage model.
ILanguageDetector
ILanguageDetector defines the interface for detecting the language of the page content.
IContentLoader
IContentLoader defines the interface for loading the content of a web page asynchronously.
WebPage
WebPage is the main model containing extracted information from a web page, including metadata, links, and source information.
Link
Link is a record that represents a hyperlink extracted from HTML content with Title and Value properties.
Source
Source is a record that contains information about the origin of web content, including the original URL and raw page content.
Extractors
The library architecture supports multiple specialized extractors that work together to build a complete representation of a web page:
- MetaDocumentExtractor - Extracts metadata from HTML <meta> tags
- OpenGraphDocumentExtractor - Extracts Open Graph protocol metadata
- TitleDocumentExtractor - Extracts the page title
- ImageDocumentExtractor - Extracts image URLs from the document
- LinksDocumentExtractor – Extracts all hyperlinks from HTML documents, converting them to strongly-typed
Linkobjects.
Content Loaders
HttpClient
HttpClientContentLoader is the default loader and is included in the main package. Without dependency injection it reuses a single shared HttpClient. To change its settings, pass your own factory and keep it for the lifetime of the application:
var factory = new HttpClientFactory(new HttpClientContentLoaderOptions
{
Timeout = TimeSpan.FromSeconds(10)
});
IExtractor extractor = new Extractor(string.Empty, new HttpClientContentLoader(factory), new LanguageDetector());
Custom Content Loader
To load pages with another HTTP library, implement IContentLoader. For example, with Flurl:
public class FlurlContentLoader : IContentLoader
{
public Task<string> Load(Uri uri, CancellationToken cancellationToken) =>
uri.ToString().GetStringAsync(cancellationToken: cancellationToken);
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- HtmlAgilityPack (>= 1.13.1)
- Microsoft.Extensions.Http (>= 10.0.12)
-
net8.0
- HtmlAgilityPack (>= 1.13.1)
- Microsoft.Extensions.Http (>= 10.0.12)
- System.Collections.Immutable (>= 10.0.14)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on X.Web.MetaExtractor:
| Package | Downloads |
|---|---|
|
X.Bluesky
Simple client for posting to Bluesky |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 136 | 10/29/2026 |
| 2.1.1 | 11,105 | 3/23/2025 |
| 2.0.4 | 6,807 | 8/1/2024 |
| 2.0.2 | 36,668 | 7/9/2024 |
| 1.8.0 | 12,421 | 3/5/2023 |
| 1.7.0 | 769 | 9/8/2022 |
| 1.5.7688.23013 | 992 | 1/18/2021 |
| 1.4.7641.34535 | 677 | 12/2/2020 |
| 1.4.7312.26620 | 980 | 1/8/2020 |
| 1.1.7147.30235 | 915 | 9/26/2019 |
| 1.1.7147.30212 | 816 | 7/27/2019 |
| 1.0.12 | 1,168 | 11/24/2018 |
| 1.0.11 | 1,008 | 11/9/2018 |
| 1.0.10 | 960 | 11/5/2018 |
| 1.0.9 | 1,144 | 9/3/2018 |
| 1.0.8 | 1,085 | 8/31/2018 |
| 1.0.7 | 1,670 | 4/26/2018 |
| 1.0.5 | 1,542 | 4/11/2018 |