Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string strCon = "Data Source=(local);database=lucene;uid=sa;pwd=qq901;";
            DataClasses1DataContext db;

            db = new DataClasses1DataContext(strCon);
            string url      = "http://quote.eastmoney.com/stocklist.html";
            string htmlbody = GetPageData(url);

            //获取 链接地址和标题

            string pattern5  = @"<a[\s\S]*?>[\s\S]*?</a>";
            string pattern11 = @"(?<=href=[\u0022\u0027]?)(?!javascript)((?<Protocol>\w+):/)?[\/]?(?<Domain>[\w.]+\/?)((?![\u0022\u0027])\S)*";


            ///定义获取标题的正则表达式
            string pattern = @"(?<=<title\s*[^>]*>).*(?=<\/title>)";

            string title = @"(?<=<a\s*[^>]*>)[\s\S]*?(?=<\/a>)";

            string pattern_dd = @"<dd[\s\S]*?>[\s\S]*?</dd>";

            htmlbody = htmlbody.Replace("<a name=\"sh\"/>", "");
            htmlbody = htmlbody.Replace("<a name=\"sz\"/>", "");
            MatchCollection matches_url_title = Regex.Matches(htmlbody, pattern5, RegexOptions.IgnoreCase);

            foreach (Match m_u_t in matches_url_title)
            {
                //寻找带下一页文字的链接全部
                if (m_u_t.Value.IndexOf("(") > -1)
                {
                    MatchCollection matches_title = Regex.Matches(m_u_t.Value, title, RegexOptions.IgnoreCase);
                    foreach (Match t in matches_title)
                    {
                        stock_id_name id_name = new stock_id_name();

                        //     MessageBox.Show(t.Value);
                        id_name.stock_name = t.Value;
                        string strTest    = t.Value;
                        int    startIndex = strTest.LastIndexOf("(") + 1;
                        int    length     = strTest.Length - strTest.IndexOf(")");


                        id_name.stock_id = strTest.Substring(startIndex, strTest.Length - length - startIndex);
                        db.stock_id_name.InsertOnSubmit(id_name);

                        ///提交插入操作
                        db.SubmitChanges();
                    }
                }
            }
            MessageBox.Show("ok!");
        }
Ejemplo n.º 2
0
 partial void Deletestock_id_name(stock_id_name instance);
Ejemplo n.º 3
0
 partial void Updatestock_id_name(stock_id_name instance);
Ejemplo n.º 4
0
 partial void Insertstock_id_name(stock_id_name instance);