@S-Soft, Welcome to Microsoft Q&A, there are two methods you could refer to to convert the url like what you wanted.
First, you could created a winform app and drag the webbrowser control to the form.
Then, you could try the following code to do it.
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri("1.html");
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Url = null;
WebClient web = new WebClient();
string htmlstr = web.DownloadString("1.html");
foreach (HtmlElement item in webBrowser1.Document.All)
{
if(item.TagName=="P")
{
string result = item.InnerText.Split(' ').Where(i => i.StartsWith("http") && i.Contains("www")).FirstOrDefault();
string str = string.Format("<a href=\"{0}\">{0}</a>", result);
htmlstr = htmlstr.Replace(result, str);
}
}
File.WriteAllText("1.html", htmlstr);
webBrowser1.Url = new Uri("1.html");
}
Second, you could try to install the nuget package HtmlAgilityPack to do it.
static void Main(string[] args)
{
WebClient web = new WebClient();
string htmlstr = web.DownloadString("1.html");
var doc = new HtmlDocument();
doc.LoadHtml(htmlstr);
foreach (var item in doc.DocumentNode.DescendantNodes())
{
if(item.Name=="p")
{
string result = item.InnerText.Split(' ').Where(i=>i.StartsWith("http")&&i.Contains("www")).FirstOrDefault();
string str = string.Format("<a href=\"{0}\">{0}</a>", result);
htmlstr=htmlstr.Replace(result, str);
}
}
File.WriteAllText("1.html", htmlstr);
}
Result:
Hope my solution could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our [documentation][3] to enable e-mail notifications if you want to receive the related email notification for this thread.