partial void Deletestock_trade_history(stock_trade_history instance);
partial void Insertstock_trade_history(stock_trade_history instance);
partial void Updatestock_trade_history(stock_trade_history instance);
private void get_stock_history() { string strCon = "Data Source=(local);database=lucene;uid=sa;pwd=qq901;"; DataClasses1DataContext db; db = new DataClasses1DataContext(strCon); string code = textBox1.Text.Trim(); for (int year = 2006; year < 2017; year++) { for (int jidu = 1; jidu < 5; jidu++) { string url = "http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/" + code + ".phtml?year=" + year.ToString() + "&jidu=" + jidu.ToString(); string htmlbody = GetPageData(url); // Response.Write(htmlbody); //获取数据表格 HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument(); htmldoc.LoadHtml(htmlbody); HtmlNode rootNode = htmldoc.DocumentNode; string s_xpath = "//table[@id='FundHoldSharesTable']"; string table = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { table = rootNode.SelectSingleNode(s_xpath).InnerHtml; // Response.Write(table); //获取股票名称 string xpath_name = "//thead[1]/tr[1]/th[1]"; //获取行元素 htmldoc.LoadHtml(table); rootNode = htmldoc.DocumentNode; string name = ""; string stock_name = ""; if (rootNode.SelectSingleNode(xpath_name) != null) { name = rootNode.SelectSingleNode(xpath_name).InnerText; name = name.Replace("年季度历史交易", ""); //llll stock_name = name; } //获取商户节点 string xpath_tr = "//tr"; // HtmlNode rootNode9 = htmldoc5.DocumentNode; HtmlNodeCollection trNodeList = rootNode.SelectNodes(xpath_tr); List <string> tr_l = new List <string>(); foreach (HtmlNode d in trNodeList) { tr_l.Add(d.InnerHtml); // Response.Write(d.InnerHtml); } foreach (string p in tr_l) { stock_trade_history stock = new stock_trade_history(); stock.stock_name = stock_name; htmldoc.LoadHtml(p); rootNode = htmldoc.DocumentNode; s_xpath = "//td[1]/div[1]/a[1]"; string riqi = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { riqi = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(riqi); stock.date = riqi; } s_xpath = "//td[2]/div[1]"; string kaipanjia = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { kaipanjia = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(kaipanjia); stock.kaipanjia = kaipanjia; } s_xpath = "//td[3]/div[1]"; string zuigaojia = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { zuigaojia = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(zuigaojia); stock.zuigaojia = zuigaojia; } s_xpath = "//td[4]/div[1]"; string soupanjia = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { soupanjia = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(soupanjia); stock.soupanjia = soupanjia; } s_xpath = "//td[5]/div[1]"; string zuidijia = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { zuidijia = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(zuidijia); stock.zuidijia = zuidijia; } s_xpath = "//td[6]/div[1]"; string jiaoyiliang = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { jiaoyiliang = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(jiaoyiliang); stock.jiaoyiliang = jiaoyiliang; } s_xpath = "//td[7]/div[1]"; string jiaoyijinge = ""; if (rootNode.SelectSingleNode(s_xpath) != null) { jiaoyijinge = rootNode.SelectSingleNode(s_xpath).InnerText; //llll // Response.Write(jiaoyijinge); stock.jiaoyijine = jiaoyijinge; } //提交数据 if (riqi != "") { db.stock_trade_history.InsertOnSubmit(stock); ///提交插入操作 db.SubmitChanges(); count++; } } } } } MessageBox.Show("获取结束!"); }