示例#1
0
        void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url != Document.Url) return;
            if (e.Url.ToString() == "http://gtj.jiangyin.gov.cn/jygt/sitePages/channelPages/135034050062404.html")
            {
                this.timer2.Interval = 3000;
                this.timer2.Start();
                return;
            }

            Model_Ground mg = new Model_Ground("江阴");
            //开始计算信息包括的字段
            List<string> arrCol = new List<string>();
            HtmlElement tRow = null;

            List<HtmlElement> listTRowSub = new List<HtmlElement>();
            List<int> listSubIndex = new List<int>();

            int headRowSpan = 1;
            try
            {
                foreach (HtmlElement td in Document.GetElementById("lk_wcms_edit_pictext701content").GetElementsByTagName("td"))
                {
                    try
                    {
                        string str = td.InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                        if (str == "宗地编号" || str == "地块编号")
                        {
                            tRow = td.Parent;
                            break;
                        }
                    }
                    catch { }
                }

                foreach (HtmlElement td in tRow.Children)
                {
                    int rowSpan = int.Parse(td.GetAttribute("rowspan"));
                    if (rowSpan > headRowSpan) headRowSpan = rowSpan;
                }

                for (int i = 1; i < headRowSpan; i++)
                {
                    listTRowSub.Add(listTRowSub.Count == 0 ? tRow.NextSibling : listTRowSub[listTRowSub.Count - 1].NextSibling);
                    listSubIndex.Add(0);
                }

                foreach (HtmlElement td in tRow.Children)
                {
                    int rowSpan = int.Parse(td.GetAttribute("rowspan"));
                    int colSpan = int.Parse(td.GetAttribute("colspan"));
                    string str = td.InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                    KeyValuePair<string, string> kvCol;
                    string strTop = regColNameFilter.Replace(str, "");
                    if (colSpan == 1)
                    {
                        str = strTop;
                        for (int i = rowSpan-1; i < headRowSpan-1; i++)
                        {
                            str += listTRowSub[i].Children[listSubIndex[i]].InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                            listSubIndex[i]++;
                        }
                        try
                        {
                            kvCol = listColName.FindAll(delegate(KeyValuePair<string, string> kv) { return kv.Key == str; })[0];
                            arrCol.Add(kvCol.Value);
                        }
                        catch
                        {
                            arrCol.Add("");
                        }
                        continue;
                    }

                    HtmlElement tRowSub = listTRowSub[rowSpan - 1];
                    for (int i = 0; i < colSpan; i++)
                    {
                        str = strTop;
                        for (int j = rowSpan - 1; j < headRowSpan - 1; j++)
                        {
                            str += listTRowSub[j].Children[listSubIndex[j]].InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                            listSubIndex[j]++;
                        }
                        //str = strTop + tRowSub.Children[i + listSubIndex[rowSpan-1]].InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                        //str = regColNameFilter.Replace(str, "");
                        try
                        {
                            kvCol = listColName.FindAll(delegate(KeyValuePair<string, string> kv) { return kv.Key == str; })[0];
                            arrCol.Add(kvCol.Value);
                        }
                        catch
                        {
                            arrCol.Add("");
                            continue;
                        }
                    }
                    //listSubIndex[rowSpan - 1] += colSpan;
                }
            }
            catch { this.NavToNext(); return; }

            mg.ClinchLink = Document.Url.ToString().Replace(".html",".jsp");

            int[] arrRowSpan = new int[arrCol.Count];

            try
            {
                Type type = typeof(Model_Ground);
                HtmlElement tr = (listTRowSub.Count == 0 ? tRow : listTRowSub[listTRowSub.Count-1]).NextSibling;
                while (tr != null)
                {
                    int offset = 0;
                    for (int i = 0; i < arrCol.Count; i++)
                    {
                        int rowSpan = 0;
                        try
                        {
                            rowSpan = int.Parse(tr.Children[i - offset].GetAttribute("rowspan")) - 1;
                        }
                        catch { }

                        if (arrCol[i] == "" || arrCol[i] == null)
                        {
                            if (arrRowSpan[i] > 0)
                            {
                                offset++;
                                arrRowSpan[i]--;
                            }
                            if (rowSpan > 0) arrRowSpan[i] = rowSpan;
                            continue;
                        }

                        if (arrRowSpan[i] > 0)
                        {
                            offset++;
                            arrRowSpan[i]--;
                            continue;
                        }

                        if (rowSpan > 0) arrRowSpan[i] = rowSpan;

                        string strValue = tr.Children[i - offset].InnerText;
                        if (strValue != null)
                        {
                            strValue = strValue.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                        }
                        FieldInfo info = type.GetField(arrCol[i]);
                        Type t = info.FieldType;

                        try
                        {
                            if (t == typeof(int))
                            {
                                try
                                {
                                    info.SetValue(mg, int.Parse(strValue));
                                }
                                catch {
                                    info.SetValue(mg, 0);
                                }
                            }
                            else if (t == typeof(double))
                            {
                                try
                                {
                                    info.SetValue(mg, double.Parse(strValue));
                                }
                                catch {
                                    info.SetValue(mg, 0);
                                }
                            }
                            else if (t == typeof(DateTime))
                            {
                                if (strValue.IndexOf("~") >= 0) strValue = strValue.Split('~')[1];
                                info.SetValue(mg, DateTime.Parse(strValue));
                            }
                            else
                            {
                                info.SetValue(mg, strValue);
                            }
                        }
                        catch { }
                    }
                    mg.GroundNum = mg.GroundNum.Replace("澄地", "").Trim();
                    mg.ClinchPrice *= 10000;
                    if(mg.ClinchPrice>0) mg.Update(listUpdateFields);
                    tr = tr.NextSibling;
                }
            }
            catch (Exception ex)
            {
                Program.MainForm.AddMessage("错误!江阴地块成交数据抓取错误。链接:" + mg.ClinchLink + "错误Id:" + mg.GroundNum + "。错误消息:" + ex.Message);
            }

            this.NavToNext();
        }
示例#2
0
        void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (e.Url != Document.Url) return;
            if (regUrl.IsMatch(e.Url.ToString()))
            {
                foreach (HtmlElement elLink in Document.GetElementsByTagName("a"))
                {
                    try
                    {
                        string strLink = elLink.GetAttribute("href");
                        if (regLink.IsMatch(strLink))
                        {
                            listLink.Add(new KeyValuePair<string, object>(strLink, elLink.InnerText));
                        }
                    }
                    catch { }
                }

                try
                {
                    HtmlElement btnNext = Document.Body.Children[2].GetElementsByTagName("input")[2];
                    if (bool.Parse(btnNext.GetAttribute("disabled"))) this.NavToNext();
                    else
                    {
                        page++;
                        this.Navigate("http://gtj.wuxi.gov.cn/BA13/D/05/index_"+page.ToString()+".shtml");
                    }
                }
                catch { this.NavToNext(); }
                return;
            }

            Model_Ground mg = new Model_Ground("无锡");
            mg.ClinchLink = Document.Url.ToString();
            //开始计算成交日期
            foreach (HtmlElement td in Document.GetElementsByTagName("td"))
            {
                if (td.InnerText!=null&&td.InnerText.Trim() == "公开日期")
                {
                    try
                    {
                        mg.ClinchDate = DateTime.Parse(td.NextSibling.InnerText);
                    }
                    catch { }
                    break;
                }
            }

            HtmlElement zoom = Document.GetElementById("Zoom");
            HtmlElement tRow = null;
            foreach (HtmlElement td in zoom.GetElementsByTagName("td"))
            {
                try
                {
                    string str = td.InnerText.Replace("\n","").Replace("\r","").Replace(" ","").Replace(" ","").Trim();
                    if (str == "编号" || str == "地块编号")
                    {
                        tRow = td.Parent;
                        break;
                    }
                }
                catch { }
            }

            //开始计算每一条成交信息
            mg.ClinchLink = linkCurrent.Key;
            try
            {
                if (tRow != null)
                {

                    List<string> arrCol = new List<string>();
                    foreach (HtmlElement td in tRow.Children)
                    {
                        string str = td.InnerText.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace(" ", "").Trim();
                        str = regColNameFilter.Replace(str, "");
                        KeyValuePair<string, string> kvCol;
                        try
                        {
                            kvCol = listColName.FindAll(delegate(KeyValuePair<string, string> kv) { return kv.Key == str; })[0];
                            arrCol.Add(kvCol.Value);
                        }
                        catch
                        {
                            arrCol.Add("");
                            continue;
                        }
                    }

                    Type type = typeof(Model_Ground);
                    HtmlElement tr = tRow.NextSibling;
                    while (tr != null)
                    {
                        if (tr.Children.Count == 0) break;
                        string strGroundNum = tr.Children[0].InnerText;
                        if (strGroundNum == null) break;
                        strGroundNum = strGroundNum.Replace("\r", "").Replace("\n", "").Trim();
                        Match mGroundNum = regGroundNum.Match(strGroundNum);
                        if (!mGroundNum.Success)
                        {
                            tr = tr.NextSibling;
                            continue;
                        }
                        mg.GroundNum = mGroundNum.Value;
                        mg.ClinchPrice = 0;
                        for (int i = 0; i < arrCol.Count; i++)
                        {
                            if (arrCol[i] == "" || arrCol[i] == null) continue;
                            string strValue = tr.Children[i].InnerText;
                            if (strValue != null)
                            {
                                strValue = strValue.Replace("\n", "").Replace("\r", "").Trim();
                            }
                            FieldInfo info = type.GetField(arrCol[i]);
                            Type t = info.FieldType;
                            try
                            {
                                if (t == typeof(int))
                                {
                                    info.SetValue(mg, int.Parse(strValue));
                                }
                                else if (t == typeof(double))
                                {
                                    info.SetValue(mg, double.Parse(strValue));
                                }
                                else if (t == typeof(DateTime))
                                {
                                    info.SetValue(mg, DateTime.Parse(strValue));
                                }
                                else
                                {
                                    info.SetValue(mg, strValue);
                                }
                            }
                            catch { continue; }
                        }
                        mg.ClinchPrice *= 10000;
                        if (mg.ClinchPrice > 0) mg.Save(true, listSaveFields);

                        tr = tr.NextSibling;
                    }

                }
                else
                {
                    MatchCollection mc = regSoldInfo.Matches(zoom.InnerText);
                    foreach (Match m in mc)
                    {
                        try
                        {
                            mg.GroundNum = m.Groups[1].Value;
                            mg.Buyer = m.Groups[7].Value;
                            if (mg.Buyer.IndexOf("由") >= 0) mg.Buyer = mg.Buyer.Split('由')[1];
                            mg.ClinchPrice = double.Parse(m.Groups[9].Value)*10000;
                            if (m.Groups[10].Value == "亿") mg.ClinchPrice *= 10000;
                            mg.Update(listSaveFields);
                        }
                        catch { }
                    }
                }
            }
            catch { }
            this.NavToNext();
        }