使用HtmlAgilityPack在网站中获取表值

时间:2015-03-03 16:16:25

标签: c# linq web-services html-agility-pack

您好我想在此网站http://proxylist.hidemyass.com

获取IP地址和PORT以及国家/地区名称

我是HtmlAgilityPack的新人,我也不认识Linq。你可以帮助我获得这些价值吗?谢谢。

1 个答案:

答案 0 :(得分:0)

 WebClient wc = new WebClient();
                string src = wc.DownloadString("http://proxylist.hidemyass.com");

                HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument();
                hd.LoadHtml(src);

                HtmlAgilityPack.HtmlNode table = hd.DocumentNode.SelectSingleNode("//tr[@class='#altshade']");

                bool First = false;
                foreach (HtmlAgilityPack.HtmlNode trs in table.ChildNodes)//.Where(i => i.Name == "tr" && i.InnerText.Trim() != string.Empty))
                {
                    if (First)
                    {
                        Proxy p = new Proxy();
                        foreach (HtmlAgilityPack.HtmlNode tds in trs.ChildNodes.Where(i => i.InnerText.Trim() != string.Empty))
                        {
                            MessageBox.Show(tds.InnerText);
                        }
                        Proxies.Add(p);
                    }
                    First = true;
                }