61
1
using System;using System.Text; using System.Linq;
2
//https://metadataconsulting.blogspot.com/2021/01/CSharp-dotNet-How-to-get-all-emails-from-a-HTML-page-with-a-href-inner-text.html
3
public class Program
4
{
5
6
/// <summary>
7
/// Extract a href with mailto (emails) links with inner text
8
/// </summary>
9
public static string ExtractEmailswithInnerText(string s)
10
{
11
string mailto = "mailto:";
12
//removal ASCII and UNICODE control characters
13
string h = new String(s.Where(c => !char.IsControl(c)).ToArray());
14
15
StringBuilder sb = new StringBuilder(h.Length);
16
17
try
18
{
19
HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
20
htmldoc.LoadHtml(h);
21
//var urls = html.DocumentNode.SelectNodes("//a[@href!='']").Select(i => i.Attributes["href"].Value);
22
23
if (htmldoc.DocumentNode.SelectNodes("//a/@href").Count > 0)
24
{
Cached Result