Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:48:27+00:00 2026-05-16T17:48:27+00:00

I have a need to verify a specific hyperlink exists on a given web

  • 0

I have a need to verify a specific hyperlink exists on a given web page. I know how to download the source HTML. What I need help with is figuring out if a “target” url exists as a hyperlink in the “source” web page.

Here is a little console program to demonstrate the problem:

public static void Main()
{
    var sourceUrl = "http://developer.yahoo.com/search/web/V1/webSearch.html";
    var targetUrl = "http://developer.yahoo.com/ypatterns/";
    Console.WriteLine("Source contains link to target? Answer = {0}",
                      SourceContainsLinkToTarget(
                          sourceUrl,
                          targetUrl));
    Console.ReadKey();
}

private static bool SourceContainsLinkToTarget(string sourceUrl, string targetUrl)
{
    string content;
    using (var wc = new WebClient())
        content = wc.DownloadString(sourceUrl);
    return content.Contains(targetUrl); // Need to ensure this is in a <href> tag!
}

Notice the comment on the last line. I can see if the target URL exists in the HTML of the source URL, but I need to verify that URL is inside of a <href/> tag. This way I can validate it’s actually a hyperlink, instead of just text.

I’m hoping someone will have a kick-ass regular expression or something I can use.

Thanks!


Here is the solution using the HtmlAgilityPack:

   private static bool SourceContainsLinkToTarget(string sourceUrl, string targetUrl)
    {
        var doc = (new HtmlWeb()).Load(sourceUrl);
        foreach (var link in doc.DocumentNode.SelectNodes("//a[@href]"))
            if (link.GetAttributeValue("href",
                                       string.Empty).Equals(targetUrl))
                return true;
        return false;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:48:28+00:00Added an answer on May 16, 2026 at 5:48 pm

    The best way is to use a web scraping library with a built in DOM parser, which will build an object tree out of the HTML and let you explore it programmatically for the link entity you are looking for. There are many available – for example Beautiful Soup (python) or scrapi (ruby) or Mechanize (perl). For .net, try the HTML agility pack. http://htmlagilitypack.codeplex.com/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to verify the integrity of a settings file. The file
I have a string which I need to verify if it's a Country code.
I need to verify a password using reqex. I have written one and tested
I have a type and an interface and I need to verify that the
Say, I have a string that I need to verify the correct format of;
i need to verify that my text box should contain only- numbers,-,/,. i have
I have a project i'm working on where i need to verify the files
I have some signed .ps1 script, I need to verify they are properly signed
I need to have a textbox on a ASP.NET page in which a user
We need to verify that download links work. And because the files are quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.