Net4x.HtmlPersist 2.0.0.26283

dotnet add package Net4x.HtmlPersist --version 2.0.0.26283
                    
NuGet\Install-Package Net4x.HtmlPersist -Version 2.0.0.26283
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Net4x.HtmlPersist" Version="2.0.0.26283" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.HtmlPersist" Version="2.0.0.26283" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.HtmlPersist" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Net4x.HtmlPersist --version 2.0.0.26283
                    
#r "nuget: Net4x.HtmlPersist, 2.0.0.26283"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Net4x.HtmlPersist@2.0.0.26283
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Net4x.HtmlPersist&version=2.0.0.26283
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.HtmlPersist&version=2.0.0.26283
                    
Install as a Cake Tool

Net4x.HtmlPersist

Scrapes the <table> of an HTML page into a System.Data.DataTable and persists it to a database: the table is created if missing, rows violating the primary key are dropped, existing rows are deleted by key and re-inserted.

Built on Net4x.BrowserLibrary for page retrieval and Net4x.DapperLibrary for persistence.

Install

dotnet add package Net4x.HtmlPersist

Target frameworks: net461, net5.0-windows, net6.0-windows, net7.0-windows, net8.0-windows. Windows only.

Requirements

A Dapper context must be registered before any persisting call, and a connection string named ConnectionString must be reachable:

using DapperLibrary.SqlServer.DbContexts;

SqlDapperContext.Use();
<connectionStrings>
  <add name="ConnectionString"
       providerName="Microsoft.Data.SqlClient"
       connectionString="Server=localhost;Database=Geography;TrustServerCertificate=True;Trusted_Connection=True;" />
</connectionStrings>

Quick start

using HtmlPersist;

SqlDapperContext.Use();

var rows = DataTablePersister.CreateInstance()
    .PersistTableFromUrl(
        url:              "https://example.com/comuni",
        tableName:        "Comuni",
        emptyTable:       true,
        maximized:        true,
        optionsToAdd:     [],
        keywordsToExclude: ["non ha prodotto risultati"],
        primaryKeys:      "Nr");

Returns the number of rows saved, 0 when the page yielded nothing or a handler cancelled, -1 when persisting threw (the exception is logged).

Get the DataTable without persisting it — extension methods on IBrowserUtility:

using var utility = BrowserUtility.CreateInstance();
var table = await utility.GetDataTableFromUrlAsync(url, maximized: true, optionsToAdd: []);
var other = await utility.GetDataTableFromPageSourceAsync(html, optionsToAdd: []);

API

DataTablePersister : IDataTablePersister

Member Purpose
CreateInstance() New persister.
PersistTableFromUrl(...) / PersistTableFromUrlAsync(...) Scrape a URL and persist; returns rows saved.
PersistDataTable(...) / PersistDataTableAsync(...) Persist a DataTable you already have.
IndexScript DDL run once, right after the table is created. Yours to supply — only you know which indexes your schema needs. Empty means no index statement.
PageDownloaded Raised with (Url, Source); set Cancel to abort.
TableObtained Raised with (Table, PrimaryKeys) before persisting; mutate the table here, or set Cancel to abort.
DataTableGetter The shared IDataTableGetter.

Rewriting a column before it is saved:

var persister = DataTablePersister.CreateInstance();
persister.TableObtained += (_, e) =>
{
    foreach (DataRow row in e.Value.Table.Rows)
        row["Provincia"] = ((string)row["Provincia"]).Replace("-", " ");
};

IDataTableGetter

Member Purpose
GetDataTableFromUrlAsync(browserUtility, url, maximized, optionsToAdd, keywordsToExclude) Loads the page and builds the table; returns null when the source contains any excluded keyword.
GetDataTableFromPageSourceAsync(browserUtility, pageSource, optionsToAdd) Builds the table from HTML you already hold.
PageDownloaded Cancellable, fires after download and before parsing.

XmlCleaner : IXmlCleaner

XmlCleaner.Instance.Clean(heading) — normalises a header cell: CRLF/LF and &nbsp; to spaces, runs of spaces collapsed, < spaced out.

Behaviour notes

  • Page source is normalised with ReplaceDiacriticsWithNormalLetters() before parsing.
  • When the first parse finds no columns, the page is fetched once more non-maximized before giving up.
  • Rows that would violate the primary key are removed, not merged.
  • emptyTable: true issues a delete from <table> before inserting.
  • PersistTableFromUrl uses a primary-key column size of 500.
Package Purpose
Net4x.BrowserLibrary The browser sessions and DOM helpers used here.
Net4x.ZipCodesLibrary Italian ZIP-code/geography downloaders built on this package.
Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net7.0-windows7.0 is compatible.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Net4x.HtmlPersist:

Package Downloads
Net4x.ZipCodesLibrary

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0.26283 54 10/11/2026
2.0.0.26238 118 8/27/2026
1.3.0.2 164 1/6/2026
1.3.0 266 4/4/2025