I'm trying to use regex to retrieve names from a website. However I get the error using "Illegal characters in path" when I run the program. Here's the code:
private void button1_Click(object sender, EventArgs e)
{
    List<string> givenNames = new List<string>();
    WebClient web = new WebClient();
    for (int i = 10000; i <= 33852; i++)
    {   
        string numberurl = i.ToString();
        string mainurl = "www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;
        String html = web.DownloadString(mainurl);
        Match m = Regex.Match(html, @"</strong>\s*(.+?)\s* ", RegexOptions.Singleline);
        string givenName = m.Groups[1].Value;
        givenNames.Add(givenName);
    }
    listBox1.DataSource = givenNames; 
}
The error occurs at String html = web.DownloadString(mainurl);. I tried using HttpUtility.UrlEncode but it still did not work. I appreciate the help.
you need to include http:// in the URL.
string mainurl = "http://www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With