Пример #1
0
        /// <summary>
        /// 获取评论信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="allComment"></param>
        /// <returns></returns>
        public static Dictionary <string, List <CommentInfo> > GetCommentInfo(string name, out List <CommentInfo> allComment)
        {
            var dic_tag         = new Dictionary <string, List <CommentInfo> >();
            var list_allComment = new List <CommentInfo>();

            Task[] tk = new Task[2];
            //获取安居客的评论数据
            tk[0] = Task.Factory.StartNew(() =>
            {
                if (ank_info != null && !string.IsNullOrWhiteSpace(ank_info.id))
                {
                    var list_comment = HouseHelperAjk.GetProjectCommenInfo(url_ajk, ank_info.id);
                    list_allComment.AddRange(list_comment);
                }
            });
            //获取房天下的评论数据
            tk[1] = Task.Factory.StartNew(() =>
            {
                bool flag = true;
                if (ank_info != null && ftx_info != null)
                {
                    //如果两个网站返回的楼盘名称不相同则证明不是同一个楼盘 试着添加住宅两个字
                    if (ank_info.name != ftx_info.name)
                    {
                        //添加住宅关键字 重新尝试获取楼盘信息 (*房天下部分楼盘名称直接带上了住宅)
                        var ftx_list = HouseHelperFtx.GetProjectInfo(url_ftx, name + "住宅");
                        if (ftx_list != null && ftx_list.Count > 0)
                        {
                            ftx_info = ftx_list[0];
                        }
                        if (ank_info.name != ftx_info.name.Replace("住宅", ""))
                        {
                            flag = false;
                        }
                    }
                }
                if (flag)
                {
                    if (ftx_info != null && !string.IsNullOrWhiteSpace(ftx_info.id) && !string.IsNullOrWhiteSpace(ftx_info.url))
                    {
                        var list_comment = HouseHelperFtx.GetProjectCommenInfo(ftx_info.url, ftx_info.id, ftx_info.commentCount);
                        list_allComment.AddRange(list_comment);
                    }
                }
            });
            //6min
            int timeout = (1000 * 60) * 6;

            Task.WaitAll(tk, timeout);
            allComment = list_allComment;
            dic_tag    = GetTag(list_allComment, name);
            //显示标签
            return(dic_tag);
        }
Пример #2
0
        /// <summary>
        /// 楼盘搜索
        /// </summary>
        /// <param name="index_city"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static List <string> ProjectSearch(int index_city, string text)
        {
            List <string> result       = new List <string>();
            var           url          = city_url[index_city].Split(',')[1];
            var           searchResult = HouseHelperAjk.SearchHouse(url, text);

            if (searchResult != null && searchResult.loupan.Count > 0)
            {
                foreach (var item in searchResult.loupan)
                {
                    var name    = item.name.Replace("<strong>", "").Replace("</strong>", "");
                    var addesss = item.addrEm.Replace("<strong>", "").Replace("</strong>", "");
                    if (name.Trim().Length >= 1)
                    {
                        result.Add(name + " [" + addesss + "]");
                    }
                }
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 获取楼盘信息
        /// </summary>
        /// <param name="city_url"></param>
        /// <param name="index_city"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ProjectInfo GetProjectInfo(int index_city, string name)
        {
            ProjectInfo p_info   = null;
            var         url_city = city_url[index_city].Split(',');

            url_ajk = url_city[1];
            url_ftx = url_city[2];
            Task[] tk = new Task[2];
            tk[0] = Task.Factory.StartNew(() =>
            {
                var ank_list = HouseHelperAjk.GetProjectInfo(url_ajk, name);
                if (ank_list != null && ank_list.Count > 0)
                {
                    //寻找最匹配项
                    foreach (var item in ank_list)
                    {
                        if (item.name == name)
                        {
                            ank_info = item;
                            break;
                        }
                    }
                    //如果没有完全匹配取第一个
                    if (ank_info == null)
                    {
                        ank_info = ank_list[0];
                    }
                }
            });
            tk[1] = Task.Factory.StartNew(() =>
            {
                var ftx_list = HouseHelperFtx.GetProjectInfo(url_ftx, name);
                if (ftx_list != null && ftx_list.Count > 0)
                {
                    //寻找最匹配项
                    foreach (var item in ftx_list)
                    {
                        //房天下数据某些楼盘名称可能出现住宅两个字
                        item.name = item.name.Replace("住宅", "");
                        if (item.name == name)
                        {
                            ftx_info = item;
                            break;
                        }
                    }
                    //如果没有完全匹配取第一个
                    if (ank_info == null)
                    {
                        ftx_info = ftx_list[0];
                    }
                }
            });
            int timeout = 1000 * 7;

            Task.WaitAll(tk, timeout);

            if (ank_info == null && ftx_info == null)
            {
                return(null);
            }
            else
            {
                if (ank_info != null)
                {
                    p_info = ank_info;
                    //如果安居客价格没有则看看房天下是否有价格数据
                    if (string.IsNullOrEmpty(ank_info.price))
                    {
                        if (ftx_info != null)
                        {
                            p_info.price = ftx_info.price;
                        }
                    }
                }
                else
                {
                    p_info = ftx_info;
                }
                p_info.price = p_info.price.Replace("均价", "").Replace("价格待定", "").Replace("广告", "");
                return(p_info);
            }
        }