---
title: "Merge contacts from multiple website pages in C#"
url: https://recursiveai.org/onecontact/cookbook/merge-contact-records-across-website-pages/
description: "Merge contacts extracted from already-loaded HTML pages of one site. Keep the page that supplied each field without crawling or fetching any URLs."
version: "1.0.0"
---

# Merge contacts from multiple website pages in C#

**OneContact** is a free, open-source contact data library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies, no network access.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact.Extraction) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp) · [Docs](https://recursiveai.org/onecontact/docs/) · [Download example (.zip)](https://recursiveai.org/onecontact/cookbook/merge-contact-records-across-website-pages/merge-contact-records-across-website-pages.zip)

Pass in the HTML you already have, then see which pages contributed to each merged contact. No URLs are fetched. The `Org` helper makes two pages for Example Studio: the home page lists an email and the contact page lists a phone.

```shell
dotnet add package RecursiveAI.OneContact.Extraction
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneContact.Extraction;

var site = new ContactExtractor().ExtractSite([
    ContactPage.FromHtml("/", Org("email",
        "hello@example.com")),
    ContactPage.FromHtml("/contact", Org(
        "telephone", "+442079460123"))]);
foreach (var record in site.Records)
    Console.WriteLine(string.Join(", ", record.Pages));

static string Org(string key, string value) => $$"""
    <script type="application/ld+json">
    { "@context": "https://schema.org",
      "@type": "Organization", "name": "Example Studio",
      "{{key}}": "{{value}}" }
    </script>
    """;
```

[The example](https://recursiveai.org/onecontact/cookbook/merge-contact-records-across-website-pages/merge-contact-records-across-website-pages.zip) is the full program below: unzip it and `dotnet run`. To run only the code above, paste it into Program.cs of a new `dotnet new console` project and `dotnet run`.

```text
/, /contact
```

## The full program

```csharp
using RecursiveAI.OneContact.Extraction;

var site = new ContactExtractor().ExtractSite([
    ContactPage.FromHtml("/", Org(
        "email", "hello@example.com")),
    ContactPage.FromHtml("/contact", Org(
        "telephone", "+442079460123"))]);
foreach (var record in site.Records)
{
    Console.WriteLine(record.Name?.Text);
    Console.WriteLine(string.Join(", ", record.Pages));
    foreach (var field in record.Fields)
        Console.WriteLine($"{field.PageId}: {field.Text}");
}

static string Org(string key, string value) => $$"""
    <script type="application/ld+json">
    { "@context": "https://schema.org",
      "@type": "Organization", "name": "Example Studio",
      "{{key}}": "{{value}}" }
    </script>
    """;
```

`dotnet run` prints:

```text
Example Studio
/, /contact
/: Example Studio
/: hello@example.com
/contact: +442079460123
```

`record.Pages` lists contributing pages for the whole organization; `field.PageId` identifies the page for that particular field. Use distinct page IDs: a duplicate ID throws `ArgumentException`.

## Variations

If you want to use field spans to highlight the original text, inspect the offset unit for each page. Insert this before the `Org` helper in the full program:

```csharp
foreach (var page in site.Pages)
    Console.WriteLine($"{page.Id}: {page.OffsetUnit}");
```

```text
/: Chars
/contact: Chars
```

## Related recipes

- [Extract contacts from HTML](https://recursiveai.org/onecontact/cookbook/extract-contacts-from-html/)
- [Deduplicate contact records](https://recursiveai.org/onecontact/cookbook/deduplicate-contacts/)

---

## The short answer

Pass a `ContactPage` for each already-loaded page to `ContactExtractor.ExtractSite`. Read `site.Records` for merged contacts and `record.Pages` for the source pages that contributed. The page ID can be a URL or any other unique label. It is never a request to download the page.

## How do you resolve duplicate contact records programmatically?

For pages from one site, OneContact extracts the records from each page, then uses matching keys to decide which records to combine. The organization name in the example joins the home page’s email to the contact page’s phone. Other matching keys include a shared non-role email and, for organizations, a non-social website. Phone numbers never decide a merge. Two organizations that list addresses but have none in common can represent separate branches: a shared email or site alone does not join them in that case, though a shared name does. The [cross-page rules](https://recursiveai.org/onecontact/docs/extraction/#pages-of-one-site) spell out the distinctions.

Copying every email and every phone into one list loses that distinction. Keep the result grouped by record, and don’t treat a company’s shared phone as proof that two named people are the same. OneContact doesn’t link a person to an employer just because the two appear on the same page; look at the links the extractor actually returns.

## How do you get rid of duplicates without losing their source pages?

One repeated field value stays as one field on the merged record. Read `Duplicates` if you need the other sightings, including their individual page IDs and spans. If the site gives competing values rather than repeating one, the extractor does not choose a winner: disagreements stay flagged. A phone on one page and a different phone on another are worth reviewing rather than silently overwriting the first.

The span is local to a field’s page. For HTML passed as strings, spans count UTF-16 code units; for byte input, they count bytes. Keep the original inputs under the same IDs if you need to highlight a field later. Use `site.Issues` to find reported parse problems and their page IDs. An empty or partial result doesn’t imply you searched every page on the site: it only represents the pages you supplied.
