コード例 #1
0
        void Browser_DocumentCompleted_Init(object sender, EventArgs e)
        {
            GeckoWebBrowser br = sender as GeckoWebBrowser;

            if (br.Url.ToString() == "about:blank")
            {
                return;
            }
            ShowClickMsg("开始加载全国的城市数据" + br.Url.ToString());
            Log.logger("开始加载全国的城市数据" + br.Url.ToString());


            foreach (Skybound.Gecko.GeckoElement a in br.Document.Links)
            {
                if (a.Parent != null &&
                    a.Parent.Parent != null &&
                    a.Parent.Parent.ClassName != null &&
                    a.Parent.Parent.ClassName == "cBox" &&
                    a.Parent.Parent.ClassName != null &&
                    a.Parent.Parent.Parent.ClassName != null &&
                    a.Parent.Parent.Parent.ClassName == "s_Box_1 hidden"
                    )
                {
                    if (!ListCItyUrl.ContainsKey(a.TextContent.Trim()))
                    {
                        ShowClickMsg(a.TextContent.Trim() + a.GetAttribute("href"));
                        ListCItyUrl.Add(a.TextContent.Trim(), a.GetAttribute("href"));
                    }
                }
            }
            //绑定到下拉框中啊
            IEUtil.CleanCookie();
            comboBox1.DataSource = ListCItyUrl.Keys.ToList();
            button1.Enabled      = true;
        }
コード例 #2
0
        protected virtual void webBrowser_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //加载成功开始分析。

            if (e.Url.ToString() == "about:blank")
            {
                return;
            }
            ShowClickMsg("开始加载全国的城市数据" + e.Url.ToString());
            Log.logger("开始加载全国的城市数据" + e.Url.ToString());
            IHTMLDocument2 doc            = (IHTMLDocument2)webBrowser.Document.DomDocument;
            ArrayList      advertiseArray = new ArrayList();

            foreach (mshtml.IHTMLElement a in doc.links)
            {
                if (a.parentElement != null &&
                    a.parentElement.parentElement != null &&
                    a.parentElement.parentElement.className != null &&
                    a.parentElement.parentElement.className == "cBox" &&
                    a.parentElement.parentElement.parentElement != null &&
                    a.parentElement.parentElement.parentElement.className != null &&
                    a.parentElement.parentElement.parentElement.className == "s_Box_1 hidden"
                    )
                {
                    if (!ListCItyUrl.ContainsKey(a.innerText.Trim()))
                    {
                        ListCItyUrl.Add(a.innerText.Trim(), a.getAttribute("href"));
                    }
                }
            }
            //绑定到下拉框中啊
            IEUtil.CleanCookie();
            comboBox1.DataSource = ListCItyUrl.Keys.ToList();
            button1.Enabled      = true;
        }
コード例 #3
0
 private void GetOneUrlandnagative()
 {
     try
     {
         //保存文件
         string name = ListCItyUrl.SingleOrDefault(a => a.Value == GetUrl()).Key;
         IEUtil.CleanTempFiles();
         List <House> housList = CItyhouseList.Where(a => a.IsSearch == false).OrderBy(a => a.ID).ToList();
         ShowLoadddingMsg(housList.Count + "/" + CItyhouseList.Count);
         if (housList.Count > 0)
         {
             House hous = housList[0];
             if (hous.urll.Length > 0)
             {
                 this.webBrowser.Navigate(hous.urll);
                 hous.IsSearch = true;
             }
         }
     }
     catch (Exception ex)
     {
         Log.logger(ex.Message + ex.StackTrace);
     }
 }
コード例 #4
0
        protected virtual void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //加载成功开始分析。
            if (e.Url.ToString() == "about:blank")
            {
                return;
            }
            ShowClickMsg("加载成功开始分析" + e.Url.ToString());
            Log.logger("加载成功开始分析" + e.Url.ToString());

            IHTMLDocument2 doc         = (IHTMLDocument2)webBrowser.Document.DomDocument;
            int            CountLoupan = 0;

            foreach (mshtml.IHTMLElement a in doc.links)
            {
                if (a.parentElement != null &&
                    a.parentElement.parentElement != null &&
                    a.parentElement.parentElement.className != null &&
                    a.parentElement.parentElement.className == "t"
                    &&
                    a.parentElement.parentElement.parentElement != null &&
                    a.parentElement.parentElement.parentElement.className != null &&
                    a.parentElement.parentElement.parentElement.className == "h3 clear" &&
                    a.parentElement.parentElement.parentElement.parentElement != null &&
                    a.parentElement.parentElement.parentElement.parentElement.className != null &&
                    a.parentElement.parentElement.parentElement.parentElement.className == "rinfo"
                    )
                {
                    CountLoupan++;
                    if (a.innerText == null)
                    {
                        continue;
                    }

                    House  hous  = new House();
                    string price = a.parentElement.parentElement.parentElement.children[1].innerText;
                    //		price.Replace("元/平米", "").Replace("均价:", "").Replace(",", "").Trim()	"起价:75万元/套"	string
                    if (price == "        ")
                    {
                        hous.Price = 0;
                    }
                    else
                    {
                        //最高价:8,016万元/套
                        int    priceint  = 0;
                        string trimprice = price.Replace(",", "");
                        if (price.IndexOf("元/平米") >= 0)
                        {
                            trimprice = price.Replace("元/平米", "").Replace("均价:", "").Replace(",", "").Replace("起价:", "").Replace("二手房参考价:", "");
                            int.TryParse(trimprice, out priceint);
                            hous.Price  = priceint;
                            hous.Danwei = "元/平米";
                        }
                        if (price.IndexOf("万元/套") >= 0)
                        {
                            trimprice = price.Replace("万元/套", "").Replace("最高价:", "").Replace(",", "").Replace("起价:", "");
                            int.TryParse(trimprice, out priceint);
                            hous.Price  = priceint;
                            hous.Danwei = "万元/套";
                        }
                    }
                    hous.Name = a.innerText;

                    HTMLDivElement isnew = (HTMLDivElement)a.parentElement.parentElement.children[1];

                    hous.HouseType = isnew.innerText;
                    // 均价:12,800元/平米
                    hous.urll = a.getAttribute("href");

                    HTMLDivElement divadd   = (HTMLDivElement)a.parentElement.parentElement.parentElement.parentElement;
                    HTMLDivElement wuye     = (HTMLDivElement)divadd.children[1];
                    string         wuyename = wuye.children[0].innerText; //物业类型:普通住宅 别墅 花园洋房

                    string phone = wuye.children[1].innerText;            //电话:400-888-2200 转 13923

                    HTMLDivElement kaifangshang = (HTMLDivElement)divadd.children[2];
                    string         address      = kaifangshang.innerText;
                    if (wuyename != null)
                    {
                        hous.wuyeleixing = wuyename.Replace("物业类型:", "");
                    }
                    else
                    {
                        hous.wuyeleixing = "无";
                    }
                    if (phone != null)
                    {
                        hous.phones = phone.Replace("电话:", "");
                    }
                    else
                    {
                        hous.phones = "无";
                    }
                    string[] kaifang_address = address.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    if (kaifang_address.Length >= 2)
                    {
                        hous.Kaifangshang = kaifang_address[1].Replace("开 发 商:", "");
                        hous.address      = kaifang_address[0].Replace("物业地址:", "");
                    }
                    else
                    {
                        hous.Kaifangshang = address;    //物业地址:大兴京开高速庞各庄出口南1000米查看地图\r\n开 发 商:北京富源盛达房地产开发有限公司
                        hous.address      = "无法识别地址";
                    }
                    ShowClickMsg(i + "_" + "楼盘:" + hous.Name + ";" + hous.Price + " " + hous.Danwei + ";" + hous.wuyeleixing + ";" + hous.phones + ";" + hous.Kaifangshang);
                    House house = CItyhouseList.SingleOrDefault(item => item.urll == hous.urll);
                    if (house == null)
                    {
                        hous.ID = AllCItyCount;
                        CItyhouseList.Add(hous);
                        AllCItyCount++;
                    }
                }
            }
            i++;
            count++;
            string urll = GetUrl() + "index.php?page=" + i;    // "http://sh.focus.cn/housemarket/house_search/index.php?page=" + i;

            ShowClickMsg(urll);
            string page = GetPage();

            if (page == "")
            {
                page = "300";
            }
            IEUtil.CleanCookie();
            IEUtil.CleanTempFiles();
            System.GC.Collect();
            if (i < int.Parse(page) && CountLoupan > 0)
            {
                this.webBrowser.Navigate(urll);
            }
            else if (CountLoupan == 0)       //没有查找到新页面了。就可以查找二级页面了。
            {
                this.webBrowser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
                this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted3);
                GetOneUrlandnagative();
            }
        }
コード例 #5
0
        protected virtual void webBrowser_DocumentCompleted3(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //加载成功开始分析。
            if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
            {
                return;
            }
            if (webBrowser.ReadyState != WebBrowserReadyState.Complete)
            {
                return;
            }
            if (e.Url.ToString() == "about:blank")
            {
                return;
            }
            IEUtil.CleanCookie();
            IEUtil.CleanTempFiles();
            System.GC.Collect();
            try
            {
                ShowClickMsg("开始加载每个楼盘的数据 " + (sender as WebBrowser).Url.AbsolutePath);
                IHTMLDocument2 doc = (IHTMLDocument2)webBrowser.Document.DomDocument;
                foreach (mshtml.IHTMLElement a in doc.links)
                {
                    if (
                        a.parentElement != null &&
                        a.parentElement.tagName != null &&
                        a.parentElement.tagName.ToLower() == "li" &&
                        a.parentElement.parentElement != null &&
                        a.parentElement.parentElement.tagName != null &&
                        a.parentElement.parentElement.tagName.ToLower() == "ul" &&
                        a.parentElement.parentElement.parentElement != null &&
                        a.parentElement.parentElement.parentElement.className != null &&
                        a.parentElement.parentElement.parentElement.className == "blockLA" &&
                        a.parentElement.parentElement.parentElement.parentElement != null &&
                        a.parentElement.parentElement.parentElement.parentElement.className != null &&
                        a.parentElement.parentElement.parentElement.parentElement.className == "l"
                        &&
                        a.parentElement.parentElement.parentElement.parentElement.parentElement != null &&
                        a.parentElement.parentElement.parentElement.parentElement.parentElement.className != null &&
                        a.parentElement.parentElement.parentElement.parentElement.parentElement.className == "area"
                        &&
                        a.parentElement.parentElement.parentElement.parentElement.parentElement.id == "contentB"
                        )
                    {
                        House house = CItyhouseList.Where(item => item.urll == (sender as WebBrowser).Url.AbsoluteUri.ToString()).ToList()[0];
                        if (house != null)
                        {
                            house.IsSearch = true;
                        }
                        else
                        {
                            GetOneUrlandnagative(); return;
                        }
                        if (house != null)
                        {
                            HTMLDivElement divinfoo = (HTMLDivElement)a.parentElement.parentElement.parentElement.parentElement.parentElement;

                            HTMLDivElement   divclass111 = (HTMLDivElement)divinfoo.children[0];
                            HTMLDivElement   divblockaaa = (HTMLDivElement)divclass111.children[0];
                            HTMLUListElement ulll1       = (HTMLUListElement)divblockaaa.children[0];
                            house.updateTime = ((HTMLLIElement)ulll1.children[0]).children[1].innerText;
                            house.AlongArea  = ((HTMLLIElement)ulll1.children[2]).innerText.Replace("所属片区:", "");

                            HTMLDivElement   divblockBBBB = (HTMLDivElement)divclass111.children[1];
                            HTMLUListElement ulllBBBB     = (HTMLUListElement)divblockBBBB.children[0];
                            house.Jiaotong   = ((HTMLLIElement)ulllBBBB.children[0]).innerText.Replace("周围交通:", "");
                            house.opentime   = ((HTMLLIElement)ulllBBBB.children[1]).innerText.Replace("开盘时间:", "");
                            house.LiveIntime = ((HTMLLIElement)ulllBBBB.children[2]).innerText.Replace("入住时间:", "");
                        }
                        string name = ListCItyUrl.SingleOrDefault(item => item.Value == GetUrl()).Key;
                        Log.Datalogger(house.ID + "," + house.Name.Replace(",", "、") + "," + house.HouseType.Replace(",", "、") + "," + house.Price + "," + house.Danwei + "," + house.phones.Replace(",", "、") + "," + house.AlongArea.Replace(",", "、") + "," +
                                       house.address.Replace(",", "、").Replace("查看地图", "") + "," + house.Kaifangshang.Replace(",", "、") + "," + house.Jiaotong.Replace(",", "、") + "," +
                                       house.opentime.Replace(",", "、") + "," + house.LiveIntime.Replace(",", "、") + "," + house.updateTime.Replace(",", "、") + "," + house.wuyeleixing.Replace(",", "、"), name);
                        break;
                    }
                }
                GetOneUrlandnagative();
            }
            catch (Exception ex)
            {
                Log.logger(ex.Message + ex.StackTrace);
                GetOneUrlandnagative();
            }
        }