标题:为什么elems.Count.ToString()总是0
只看楼主
千面
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-2-25
结帖率:100%
已结贴  问题点数:5 回复次数:2 
为什么elems.Count.ToString()总是0
private void button1_Click(object sender, EventArgs e)
        {
            string result = null;
            string url = "http://www.baidu.com/";
            WebResponse response = null;
            StreamReader reader = null;

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "GET";
                response = request.GetResponse();
                reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                result = reader.ReadToEnd();

                WebBrowser b = new WebBrowser();
                b.DocumentText = result;
                HtmlDocument doc = b.Document;
                HtmlElementCollection elems = null;

                if (doc != null)
                {
                    elems = doc.GetElementsByTagName("a");
                    textBox1.Text = elems.Count.ToString();//为什么运行结果总是0
              }
        }
搜索更多相关主题的帖子: Count ToString elems 
2010-05-27 22:45
千面
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2010-2-25
得分:0 
自己先顶一下!我的点数很少,各位可能瞧不上,但是恳求各位帮忙解答一下!
2010-05-27 22:46
qubo1982
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:367
专家分:1132
注 册:2009-3-18
得分:5 
设个断点调试一下吧,看看
elems = doc.GetElementsByTagName("a");
执行后是不是得到了有意义的结果
2010-05-29 08:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-308422-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025493 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved