我正在尝试使用正则表达式从网站检索名称。但是,当我运行程序时,使用“路径中的非法字符”出现错误。这是代码:
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;
}
错误发生在String html = web.DownloadString(mainurl);
。我尝试使用HttpUtility.UrlEncode
,但仍然无法正常工作。我很感激帮助。