コード例 #1
0
ファイル: WuXi_DailySold.cs プロジェクト: hifans/capdata
        void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url != Browser.Url) return;

            try
            {
                HtmlElement tbody = Document.GetElementById("statinfo").Children[0];
                HtmlElement tr = tbody.Children[1];
                Model_DailySold mds = new Model_DailySold("无锡");
                //mds.SoldCount = int.Parse(tr.Children[1].InnerText.Replace("套", ""));
                //mds.SoldArea = double.Parse(tr.Children[2].InnerText.Replace("m2", ""));
                //mds.avePrice = double.Parse(tr.Children[3].InnerText.Replace("万元", ""));
                //if (mds.SoldArea > 0) mds.avePrice = mds.avePrice * 10000 / mds.SoldArea;
                //mds.Save();

                if (Fn.GetDT_MySQL("select * from city_dailysold where cityid=" + mds.CityId + " and soldDate='" + DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd") + "'").Rows.Count == 0)
                {
                    //抓取前一天数据
                    tr = tbody.Children[2];
                    mds.SoldDate = mds.SoldDate.AddDays(-1);
                    mds.SoldCount = int.Parse(tr.Children[1].InnerText.Replace("套", ""));
                    mds.SoldArea = double.Parse(tr.Children[2].InnerText.Replace("m2", ""));
                    try
                    {
                        mds.avePrice = double.Parse(tr.Children[3].InnerText.Replace("万元", ""));
                    }
                    catch { }
                    if (mds.SoldArea > 0) mds.avePrice = mds.avePrice * 10000 / mds.SoldArea;
                    mds.Save();
                }

            }
            catch(Exception ex) {
                Program.MainForm.AddMessage("无锡每日成交信息抓取失败!错误消息:"+ex.Message);
            }

            this.Close();
        }
コード例 #2
0
ファイル: WuXi_DailySold2.cs プロジェクト: hifans/capdata
        void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url != Document.Url) return;
            if (e.Url.ToString().StartsWith("http://www.wxhouse.com/YanJiu/list.html?PageIndex="))
            {
                foreach (HtmlElement link in Document.GetElementsByTagName("a"))
                {
                    try
                    {
                        string strLink = link.GetAttribute("href");
                        if (regLink.IsMatch(strLink)) listLink.Add(new KeyValuePair<string, object>(strLink, null));
                    }
                    catch { }
                }
                this.NavToNextPage();
                return;
            }

            try
            {
                DateTime dateRelease = DateTime.Today;
                foreach (HtmlElement span in Document.GetElementsByTagName("span"))
                {
                    if (span.GetAttribute("classname") == "div_intro")
                    {
                        dateRelease = Convert.ToDateTime("20" + span.InnerText);
                        break;
                    }
                }

                string cont = Document.GetElementById("content").InnerText;
                MatchCollection mcAll = regAll.Matches(cont);
                MatchCollection mcRes = regRes.Matches(cont);
                MatchCollection mcResPrice = regResPrice.Matches(cont);

                Model_DailySold mds = new Model_DailySold("无锡");
                foreach (Match mAll in mcAll)
                {
                    DateTime date = Convert.ToDateTime(DateTime.Today.Year + "年" + mAll.Groups[1].Value);
                    while(date > dateRelease) date = date.AddYears(-1);

                    mds.SoldDate = date;
                    double areaAll = double.Parse(mAll.Groups[2].Value);
                    int countAll = int.Parse(mAll.Groups[3].Value);
                    double priceAll = 0;

                    double areaRes = 0;
                    int countRes = 0;
                    double priceRes = 0;

                    string sFilter = "cityId='" + mds.CityId + "' and soldDate='" + date.ToString("yyyy-MM-dd") + "'";
                    try
                    {
                        priceAll = double.Parse(Fn.GetObj_MySQL("select sum(soldArea*avePrice)/sum(soldArea) from city_dailysold where " + sFilter + " limit 1").ToString());
                    }
                    catch { }

                    foreach (Match m in mcRes)
                    {
                        DateTime dateTmp = Convert.ToDateTime(DateTime.Today.Year + "年" + m.Groups[1].Value);
                        while (dateTmp > dateRelease) dateTmp = dateTmp.AddYears(-1);
                        if (dateTmp == date)
                        {
                            areaRes = double.Parse(m.Groups[2].Value);
                            countRes = int.Parse(m.Groups[3].Value);
                            break;
                        }
                    }

                    foreach (Match m in mcResPrice)
                    {
                        DateTime dateTmp = Convert.ToDateTime(DateTime.Today.Year + "年" + m.Groups[1].Value);
                        while(dateTmp > dateRelease) dateTmp = dateTmp.AddYears(-1);
                        if (dateTmp == date)
                        {
                            priceRes = double.Parse(m.Groups[2].Value);
                            break;
                        }
                    }

                    if (countRes > 0)
                    {
                        Fn.ExecNonQuery_MySQL("delete from city_dailysold where " + sFilter+" and soldUsage='商品房'");
                        if (priceRes == 0) priceRes = priceAll;
                        mds.SoldUsage = "住宅";
                        mds.SoldCount = countRes;
                        mds.SoldArea = areaRes;
                        mds.avePrice = priceRes;
                        mds.Save();

                        mds.SoldUsage = "其他";
                        mds.SoldCount = countAll - countRes;
                        mds.SoldArea = areaAll - areaRes;
                        mds.avePrice = priceAll == 0 ? 0 : ((priceAll * areaAll - priceRes * areaRes) / mds.SoldArea);
                        mds.Save();
                    }
                    else
                    {
                        mds.SoldUsage = "商品房";
                        mds.SoldArea = areaAll;
                        mds.SoldCount = countAll;
                        mds.avePrice = priceAll;
                        mds.Save();
                    }
                }

            }
            catch { }
            this.NavToNext();
        }