做过股票的人都知道要选一个好股票往往要用到技术指标选股,而有时自己会有一些想法,想用其来挑选股票,并用历史数据进行校验,必须要有每日的数据,下面是我自己写的一个抓数据的C#代码。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
namespace 股票技术分析{ public partial class Form3 : Form { string conn = System.Configuration.ConfigurationManager.ConnectionStrings["BusinessConnString"].ConnectionString; string stockcode = ""; DataTable dt; int Count = 0; string beginday; string endday; public Form3() { InitializeComponent(); }
private void Form3_Load(object sender, EventArgs e) { DataSet ds = Platform.Data.SqlHelper.ExecuteDataset(conn, CommandType.Text, "select * from StockCodeInformation where IsActive=0 order by stockcode"); dt = ds.Tables[0]; stockcode = dt.Rows[0]["stockcode"].ToString();
beginday = (1991 ).ToString() + "-01-01"; endday = (1991 ).ToString() + "-12-31"; webBrowser1.Url = new Uri(@"http://app.finance.ifeng.com/hq/stock_daily.php?code=" + stockcode + "&begin_day=" + beginday + "&end_day=" + endday); }
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { string sql = "update StockCodeInformation set IsActive=1 where stockcode = '" + stockcode + "'"; Platform.Data.SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql);
if (Count < dt.Rows.Count) { Count++; stockcode = dt.Rows[Count]["stockcode"].ToString(); webBrowser1.Url = new Uri(@"http://app.finance.ifeng.com/hq/stock_daily.php?code=" + stockcode + "&begin_day=" + beginday + "&end_day=" + endday); } } }}