Esempio n. 1
0
        /// <summary>
        /// 县
        /// </summary>
        /// <param name="uri">页面URL地址</param>
        /// <param name="domCode">HTML代码</param>
        /// <param name="parentNode">父节点</param>
        private void GetCounty(Uri uri, string domCode, TreeNode parentNode)
        {
            string _pattern = "<tr class=(\"|')countytr(\"|')>([\\s\\S]*?)<\\/tr>";

            string[] _trDoms = MatchHelper.GetStrings(domCode, _pattern);

            foreach (string _trDomStr in _trDoms)
            {
                ArrayList _alLinks = MatchHelper.GetHTMLATag(_trDomStr);
                if (_alLinks.Count > 0 && _alLinks.Count % 2 == 0)
                {
                    string _strCUrl  = MatchHelper.GetHrefString(_alLinks[0].ToString());
                    string _areaId   = MatchHelper.RemoveHtmlTag(_alLinks[0].ToString()).Substring(0, 6);
                    string _areaName = MatchHelper.RemoveHtmlTag(_alLinks[1].ToString());

                    TreeNode _treeNode = new TreeNode()
                    {
                        Text = $"{_areaName}({_areaId})"
                    };

                    AddNodeToAreaTreeView(_treeNode, parentNode);

                    if (_treeNode != null)
                    {
                        // 获取下级区域信息,如果有则加载
                        Uri _uriChildren; // 下级区域的Url地址
                        if (Uri.TryCreate(uri, _strCUrl, out _uriChildren))
                        {
                            string _url = _uriChildren.AbsoluteUri;

                            // 获取数据
                            string _childrenPageDom = _httpHelper.GetHtml(_url, encode, false);

                            if (!string.IsNullOrWhiteSpace(_childrenPageDom) && !_childrenPageDom.Equals("404"))
                            {
                                GetTown(_uriChildren, _childrenPageDom, _treeNode);
                            }
                        }
                    }
                }
            }
        }