我是动漫迷,我想获得所有动漫角色的完整列表,所以我遇到了这个网站: http ://www.animevice.com/characters/?page=1 我的目标是提取所有名称并添加他们到listBox1。这是我当前的代码:
try
{
while (true)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.animevice.com/characters/?page=" + n);
req.Method = "GET";
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0";
req.KeepAlive = true;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream responseData = response.GetResponseStream();
StreamReader reader = new StreamReader(responseData);
string responseFromServer = reader.ReadToEnd();
string m = "<a href=\"(.*)\" class=\"name\">(.*)</a>";
Match match = Regex.Match(responseFromServer, m, RegexOptions.IgnoreCase);
if (match.Success)
{
listBox1.Items.Add(match.Groups[2]Value.ToString());
}
if (listBox1.Items.Count % 50 == 0)
{
n++;
}
}
}
catch { }
然而,这给了我很多次名单上的第一个名字(Monkey D. Luffy)。有什么解决办法吗?干杯