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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:25:22+00:00 2026-05-31T21:25:22+00:00

Something dosent work good with the text() function why ? For example if im

  • 0

Something dosent work good with the text() function why ?
For example if im going to http://www.walla.co.il in internet explorer and view the source i see that the first url address there is http://www.w3.org

But in textBox2 i see the first url address as: http://www.yad1.yad2.co.il

And i want to parse all the url’s from the site and show them in textBox2
In textBox1 i just show thew hole content.

This is the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

namespace WebCrawler
{
    public partial class Form1 : Form
    {
        StreamWriter sw;
        string url = "http://www.walla.co.il";
        StringBuilder sb;
        HttpWebRequest req;
        HttpWebResponse res;


        public Form1()
        {
            InitializeComponent();
            sw = new StreamWriter(@"d:\text.txt");
            req = (HttpWebRequest)WebRequest.Create(url);
            sb = new StringBuilder();
            WebRequestGetExample("http://www.walla.co.il");
            text();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        public string WebRequestGetExample(string url)
        {
            //validateUrl(url);              
            req.Method = "Get";
            res = (HttpWebResponse)req.GetResponse();
            // Display the status.  
            Console.WriteLine(res.StatusDescription);
            // Get the stream containing content returned by the server.  
            Stream dataStream = res.GetResponseStream();
            // Open the stream using a StreamReader for easy access.  
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.  
            string t = reader.ReadToEnd();
            // Display the content.  
            textBox1.Text = t;
            // Cleanup the streams and the response.  
            reader.Close();
            dataStream.Close();
            res.Close();

            return t;
        }

       /* public void text()
        {
            string val;
            StringBuilder sb = new StringBuilder();
            Regex hrefs = new Regex("<a href.*?>");
            Regex http = new Regex("http:.*?>");
            foreach (Match m in hrefs.Matches(textBox1.Text))
            {

                //sb.Append(m.ToString());
                if (http.IsMatch(m.ToString()))
                {

                    val = http.Match(m.ToString()).ToString();
                    int end = val.IndexOf('"');
                    if (end > 0)
                        sb.Append(val.Substring(0, end));
                    //sb.Append("<br>");
                }
                else
                {
                    val = http.Match(m.ToString()).ToString();
                    sb.Append(val);
                    //sb.Append(m.ToString().Substring(1, m.ToString().Length - 1) + "<br>");

                }

                textBox2.Text = sb.ToString();
            }

        }*/

        public void text()
        {
            StringBuilder sb = new StringBuilder();
            Regex hrefs = new Regex("<a href.*?>");
            Regex http = new Regex("http:.*?>");
            foreach (Match m in hrefs.Matches(textBox1.Text))
            {
                //sb.Append(m.ToString());
                if (http.IsMatch(m.ToString()))
                {
                    string val = http.Match(m.ToString()).ToString();
                    int end = val.IndexOf('"');
                    sb.Append(end > 0 ? val.Substring(0, end) : val);
                    //if (end > 0)
                    //    sb.Append(val.Substring(0, end));
                    //else
                    //    sb.Append(val);
                    //sb.Append("<br>");
                }
                else
                {
                    //sb.Append(m.ToString().Substring(1, m.ToString().Length - 1) + "<br>");
                }
                textBox2.Text = sb.ToString();
                sw.WriteLine(sb.ToString());
            }
            sw.Close();
        }
    }
}
  • 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-31T21:25:23+00:00Added an answer on May 31, 2026 at 9:25 pm

    The match you are looking for is looking for an actual link
    <[ignore]a href….>
    but the first link you see in the source (the w3c link) is in the head. If you want to get that you would have to remove the hrefs match (eg just find links on the page) or modify it to match

    <html lang="he-IL" xml:lang="he-IL" xmlns="http://www.w3.org/1999/xhtml">
    

    However, I suspect you do only want to find links so your code is working correctly.

    Sorry about the ignore, StackOverflow kept converting it into actual link 😛

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

Sidebar

Related Questions

Something like var life= { users : { guys : function(){ this.SOMETHING.mameAndDestroy(this.girls); }, girls
Something really weird is going on with Xcode and an iPhone project I'm working
If I pass Label1.Text through a function it treats it as an object and
Possible Duplicate: Why doesn't System.out.println work? (in Android) I want to print something into
I tried making custom tags so that uses can enter text that displays something
That's important for good documentation, but currently it just doesnt work well. If I
If you look at the source code for the html you can see the
Something i've never really done before, but what is the best way to make
Something I have always been interested in out of curiosity, is there a tool
Something that has always bugged me is how unpredictable the setTimeout() method in Javascript

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.