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; }
private void button1_Click(object sender, EventArgs e) { try { string name = ListCItyUrl.SingleOrDefault(a => a.Value == GetUrl()).Key; Log.FileDelete(name); Log.Datalogger("" + "," + "楼盘" + "," + "开盘" + "," + "价格" + "," + "单位" + "," + "电话" + "," + "片区" + "," + "地址" + "," + "开发商" + "," + "交通情况" + "," + "开盘时间" + "," + "入住时间" + "," + "更新时间" + "," + "物业情况", name); CItyhouseList.Clear(); beginSearch(); } catch (Exception ex) { Log.logger(ex.ToString()); MessageBox.Show("button1_Click" + ex.ToString()); } }
private void GetOneUrlandnagative() { try { //保存文件 string name = ListCItyUrl.SingleOrDefault(a => a.Value == GetUrl()).Key; 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.Browser.Navigate(hous.urll); hous.IsSearch = true; } } } catch (Exception ex) { Log.logger(ex.Message + ex.StackTrace); } }
void Browser_DocumentCompleted_xiangxi(object sender, EventArgs e) { GeckoWebBrowser br = sender as GeckoWebBrowser; if (br.Url.ToString() == "about:blank") { GetOneUrlandnagative(); return; } System.GC.Collect(); try { ShowClickMsg("开始加载每个楼盘的数据 " + br.Url.ToString()); foreach (Skybound.Gecko.GeckoElement a in br.Document.Links) { if ( a.Parent != null && a.Parent.TagName != null && a.Parent.TagName.ToLower() == "li" && a.Parent.Parent != null && a.Parent.Parent.TagName != null && a.Parent.Parent.TagName.ToLower() == "ul" && a.Parent.Parent.Parent != null && a.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.ClassName == "blockLA" && a.Parent.Parent.Parent.Parent != null && a.Parent.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.Parent.ClassName == "l" && a.Parent.Parent.Parent.Parent.Parent != null && a.Parent.Parent.Parent.Parent.Parent.ClassName != null && a.Parent.Parent.Parent.Parent.Parent.ClassName == "area" && a.Parent.Parent.Parent.Parent.Parent.Id == "contentB" ) { House house = CItyhouseList.Where(item => item.urll == br.Url.ToString()).ToList()[0]; if (house != null) { house.IsSearch = true; } else { GetOneUrlandnagative(); return; } if (house != null) { Skybound.Gecko.GeckoElement divinfoo = (Skybound.Gecko.GeckoElement)a.Parent.Parent.Parent.Parent.Parent; Skybound.Gecko.GeckoNode divclass111 = (Skybound.Gecko.GeckoNode)divinfoo.ChildNodes[1]; Skybound.Gecko.GeckoNode divblockaaa = (Skybound.Gecko.GeckoNode)divclass111.ChildNodes[1]; Skybound.Gecko.GeckoNode ulll1 = (Skybound.Gecko.GeckoNode)divblockaaa.ChildNodes[1]; house.updateTime = ((Skybound.Gecko.GeckoNode)ulll1.ChildNodes[1]).ChildNodes[1].TextContent; house.AlongArea = ((Skybound.Gecko.GeckoNode)ulll1.ChildNodes[5]).TextContent.Replace("所属片区:", ""); Skybound.Gecko.GeckoNode divblockBBBB = (Skybound.Gecko.GeckoNode)divclass111.ChildNodes[3]; Skybound.Gecko.GeckoNode ulllBBBB = (Skybound.Gecko.GeckoNode)divblockBBBB.ChildNodes[1]; house.Jiaotong = ((Skybound.Gecko.GeckoNode)ulllBBBB.ChildNodes[1]).TextContent.Replace("周围交通:", ""); house.opentime = ((Skybound.Gecko.GeckoNode)ulllBBBB.ChildNodes[3]).TextContent.Replace("开盘时间:", ""); house.LiveIntime = ((Skybound.Gecko.GeckoNode)ulllBBBB.ChildNodes[5]).TextContent.Replace("入住时间:", ""); } string name = ListCItyUrl.SingleOrDefault(item => item.Value == GetUrl()).Key; Log.Datalogger(house.ID + "," + GetRightString(house.Name.Replace(",", "、")) + "," + GetRightString(house.HouseType.Replace(",", "、")) + "," + house.Price + "," + GetRightString(house.Danwei) + "," + GetRightString(house.phones.Replace(",", "、")) + "," + GetRightString(house.AlongArea.Replace(",", "、")) + "," + house.address.Replace(",", "、").Replace("查看地图", "") + "," + GetRightString(house.Kaifangshang.Replace(",", "、")) + "," + GetRightString(house.Jiaotong.Replace(",", "、")) + "," + GetRightString(house.opentime.Replace(",", "、")) + "," + GetRightString(house.LiveIntime.Replace(",", "、")) + "," + GetRightString(house.updateTime.Replace(",", "、")) + "," + GetRightString(house.wuyeleixing.Replace(",", "、")), name); break; } } GetOneUrlandnagative(); } catch (Exception ex) { Log.logger(ex.Message + ex.StackTrace); GetOneUrlandnagative(); } }
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(); } }