我试图使用正则表达式从某些文本中获取匹配项,但代码无法产生任何结果。
正文包含
action="https://www.localhost.com/en/account?dwcont=C338711466"
我的代码是
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.localhost.com/en/account");
httpWebRequest.Method = "GET";
httpWebRequest.CookieContainer = this.cookieJar;
string text2;
using (StreamReader streamReader = new StreamReader(httpWebRequest.GetResponse().GetResponseStream()))
{
string text = streamReader.ReadToEnd().Trim().ToString();
string[] array = (from Match match in Regex.Matches(text, "\"https://www.localhost.com/en/account?dwcont=(.+?)\"")
select match.Groups[1].Value).ToArray<string>();
text2 = array[0];
}
MessageBox.Show(text2);
我在数组中收到错误:
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
有解决办法吗?
慕无忌1623718
相关分类