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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:23:54+00:00 2026-05-14T07:23:54+00:00

I am in process of getting all hierarchical links from a given link and

  • 0

I am in process of getting all hierarchical links from a given link and validating them;
This is the code I wrote. But I am not feeling it as efficient.

Reasons are:

1.For the non unique links which open same page, code is getting sub-links again and again

2.Is the code getting all links?

3.Is it making valid URLs from the sub-links it derived?

4.May be some other reasons about which I have no idea.

Please suggest me how to make this piece of code efficient .
Thank you.

class Program

{

        public static ArrayList sublink = new ArrayList();
        public static ArrayList subtitle = new ArrayList();
        public static int ini = 0, len_o, len_n, counter = 0;
        static void Main(string[] args)
        {
         // Address of URL
            string URL = "http://www.techonthenet.com/"; 
        sublink.Add(URL);
    l:
        len_o = sublink.Count; len_o); 
        Console.WriteLine("-------------Level:" + counter++);
            for (int i = ini; i < len_o; i++) test(sublink[i].ToString());

        len_n = sublink.Count; 
        if (len_o < len_n) { ini = len_o; goto l; }

        Console.ReadKey();

        }
        //method to get the sub-links
        public static void test(string URL)
        {
            try
            {
                // Get HTML data 
                WebClient client = new WebClient();
                Stream data = client.OpenRead(URL);
                StreamReader reader = new StreamReader(data);

                string str = "", htmldata = "", temp;
                int n1, n2;
                str = reader.ReadLine();
                while (str != null)
                {
                    htmldata += str;
                    str = reader.ReadLine();

                }
                data.Close();
                    for (int i = 0; i < htmldata.Length - 5; i++)
                    {
                        if (htmldata.Substring(i, 5) == "href=")
                        {
                            n1 = htmldata.Substring(i + 6, htmldata.Length - (i + 6)).IndexOf("\"");
                            temp = htmldata.Substring(i + 6, n1);
                            if (temp.Length > 4 && temp.Substring(0, 4) != "http")
                            {   
                                if(temp.Substring(0,1)!="/")
                                temp=URL.Substring(0,URL.IndexOf(".com/")+5)+temp;
                                else temp = URL.Substring(0, URL.IndexOf(".com/") + 5) + temp.Remove(0,1);
                            }
                            if (temp.Length < 4) temp = URL.Substring(0, URL.IndexOf(".com/") + 5) + temp;
                            sublink.Add(temp);
                            n2 = htmldata.Substring(i + n1 + 1, htmldata.Length - (i + n1 + 1)).IndexOf("<");
                            subtitle.Add(htmldata.Substring(i + 6 + n1 + 2, n2 - 7));
                            i += temp.Length + htmldata.Substring(i + 6 + n1 + 2, n2 - 7).Length; 

                        }
                    }


                    for (int i = len_n; i < sublink.Count; i++) Console.WriteLine(i + "-->  " + sublink[i]);

            }
            catch (WebException exp)
            {
                Console.WriteLine("URL Could not be Resolved" + URL);
                Console.WriteLine(exp.Message, "Exception");
            }

        }
        } 
  • 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-14T07:23:55+00:00Added an answer on May 14, 2026 at 7:23 am

    Why not using regular expressions? They are easier to read, debug and mantain.
    Also check out the Uri class. It has a couple of useful helpers (e.g. for base-relative url manipulation).

    Also consider using an html/xml parser. There already was a discussion here.
    Parsing html as plain text (i.e. with regular expressions) seems to be easy at first, but it may soon become painful to add new features to your parser.

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

Sidebar

Related Questions

I've tried getting the launch link from the start menu and using Process.Start() But
I need to automate a process that involves getting data from a series of
I am getting this Exception application openwnn (process jp.co.omronsoft.openwnn) has stopped in the emulator
I keep getting this error randomly: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request.
This is more of a question about getting my head around the process I
I need a way for getting all of the file handles of a given
I am just going through one scenario, where I am not at all getting
Have been hearing all around ArrayList getting obsolete these days. But I do have
Is this possible to get all my friends likes?? Now, I'm getting this by
I've posted a couple other questions during this process, but I have a better

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.