gpt4 book ai didi

c# - 带有 web.downloadstring 的路径中的非法字符

转载 作者:太空狗 更新时间:2023-10-30 00:15:43 25 4
gpt4 key购买 nike

我正在尝试使用正则表达式从网站检索名称。但是,当我运行该程序时,使用“路径中的非法字符”出现错误。这是代码:

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*&nbsp;", RegexOptions.Singleline);

string givenName = m.Groups[1].Value;
givenNames.Add(givenName);
}
listBox1.DataSource = givenNames;
}

错误发生在 String html = web.DownloadString(mainurl);。我尝试使用 HttpUtility.UrlEncode 但它仍然无效。感谢您的帮助。

最佳答案

您需要在 URL 中包含 http://。

string mainurl = "http://www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;

关于c# - 带有 web.downloadstring 的路径中的非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11800480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com