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

  • Home
  • SEARCH
  • 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 8032027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:16:18+00:00 2026-06-05T01:16:18+00:00

I’m having trouble configuring a web scraper that i’m working on for a project

  • 0

I’m having trouble configuring a web scraper that i’m working on for a project i’ve on the go at present

I’m trying to scrape a series of links from a page in order to assess which ones I want to process. Here is my code:

public partial class Form1 : Form
{
    private byte[] aRequestHTML;
    private string sourceString = null;
    string[] a;
    WebClient objWebClient = new WebClient();
    LinkScraper linkScraper = new LinkScraper();

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        ScrapeLinks(textBox1.Text);
    }


    public void ScrapeLinks(string sourceLink)
    {
        // gets the HTML from the url written in the textbox
        aRequestHTML = objWebClient.DownloadData(sourceLink);
        // creates UTf8 encoding object
        UTF8Encoding utf8 = new UTF8Encoding();
        // gets the UTF8 encoding of all the html we got in aRequestHTML
        sourceString = utf8.GetString(aRequestHTML);
        // this is a regular expression to check for the urls 
        Regex r = new Regex("\\<a\\shref\\=(.*)\\>(.*)\\<\\/a\\>");
        // get all the matches depending upon the regular expression
        MatchCollection mcl = r.Matches(sourceString);

        a = new string[mcl.Count];
        int i = 0;
        foreach (Match ml in mcl)
        {
            // Add the extracted urls to the array list
            a[i] = ml.ToString();
            Console.WriteLine(a[i]);
            i++;
        }

        dataGridView1.DataSource = a;
        // binds the databind

        // The following lines of code writes the extracted Urls to the file named test.txt
        StreamWriter sw = new StreamWriter("test.txt");
        foreach (string aElement in a)
        {
            sw.Write(aElement + "\n");
        }
        sw.Close();
    }
}

My issue arises from setting my datagrid datasource. Instead of the datagrid being populated with the list of strings it is populated with each strings length instead. As you will see i’ve a test.txt file writing out to see if I was doing something stupid but the text file contains each string as i’d expect to see it in the datagrid

I’ve trawled the forums for 12 hrs for a solution but with no joy

Could someone be kind enough to advise why the .Value is not returning my strings into the string array ‘a’ for binding to the datagrid?

Any help is as always greatly appreciated

Regards
Barry

  • 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-06-05T01:16:19+00:00Added an answer on June 5, 2026 at 1:16 am

    Found the solution folks just now

    DataGridView displays the first property it can find for a string which is its length property
    Workaround is to use a DataTable

     DataTable links = new DataTable();
     links.Columns.Add("Link URL");
    
     foreach (Match ml in mcl)
     {
       // Add the extracted urls to table
       links.Rows.Add(new object[] {ml.Value});
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.