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 6781049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:34:43+00:00 2026-05-26T16:34:43+00:00

I want to be able to scrape a webpage containing multiple <a href -tags

  • 0

I want to be able to scrape a webpage containing multiple “<a href“-tags and return a structured collection of them.

<div>
    <p>Lorem ipsum... <a href="https://stackoverflow">Classic link</a>
        <a title="test" href=http://sloppy-html-5-href.com>I lovez HTML 5</a>
    </p>
    <a class="abc" href='/my-tribute-to-javascript.html'>I also love JS</a>
    <iframe width="420" height="315" src="http://www.youtube.com/embed/JVPT4h_ilOU"
        frameborder="0" allowfullscreen></iframe><!-- Don't catch me! -->
</div>

So I want these values:

  • https://stackoverflow | Classic link
  • http://sloppy-html-5-href.com | I lovez HTML 5
  • /my-tribute-to-javascript.html | I also love JS

As you can see, only values in an “a href” should be caught, with both link and content within the tags. It should support all HTML 5-valid href. The href-attributes can be surrounded with any other attributes.

So I basically want a regex to fill in the following code:

public IEnumerable<Tuple<string, string>> GetLinks(string html) {
     string pattern = string.Empty; // TODO: Get solution from Stackoverflow
     var matches = Regex.Matches(html, pattern);

     foreach(Match match in matches) {
         yield return new Tuple<string, string>(
             match.Groups[0].Value, match.Groups[1].Value);
     }
}
  • 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-26T16:34:43+00:00Added an answer on May 26, 2026 at 4:34 pm

    I’ve always read that parsing Html with Regular Expression is the Evil. Ok… it’s surely true…
    But like the Evil, Regex are so fun 🙂
    So I’d give a try to this one:

    Regex r = new Regex(@"<a.*?href=(""|')(?<href>.*?)(""|').*?>(?<value>.*?)</a>");
    
    foreach (Match match in r.Matches(html))
        yield return new Tuple<string, string>(
            match.Groups["href"].Value, match.Groups["value"].Value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want to be able to provide a search interface for a collection of objects
I am able to scrape a page for URLs, but I want to know
On my webpage I want to able to present tabular data and give the
I'm using LaTeX and BibTeX for an article, and I want to able to
I want to be able to capture the exception that is thrown when a
I want to be able to do: For Each thing In things End For
I want to be able to play sound files in my program. Where should
I want to be able to make an HTTP call updating some select boxes
I want to be able to view a SQL Server 2005 Reporting Services report
I want to be able to do this. MyInterface interface = new ServiceProxyHelper<ProxyType>(); Here's

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.