public GuoJiPrice GetGuoJiPriceInfo(string url)
{
GuoJiPrice result = null;
try
{
string now = DateTime.Now.ToString("yyyy-MM-dd");
url = string.Format("{0}_{1}_{1}_1.htm", url, now);
string form = Http.GetHtml(url, ref cookie);
string form2 = Other.GetRegValue("<table width='100%' border='0' cellspacing='0' cellpadding='0' class='ProTab marginT'><tr((?!</table>).)+",form);
MatchCollection trmatches = Other.GetRegValues("<tr><td((?!</tr>).)+", form2);
foreach (Match match in trmatches)
{
MatchCollection matches = Other.GetRegValues("<td((?!</td>).)+", match.Value);
string a = Other.GetRegValue(@".*", matches[1].Value.Replace("<td align='center'> ", ""));
string b = Other.GetRegValue(@".*", matches[2].Value.Replace("<td align='center'> ", ""));
string c = Other.GetRegValue(@".*", matches[3].Value.Replace("<td align='center'> ", ""));
string d = Other.GetRegValue(@".*", matches[4].Value.Replace("<td><span class='down'>", " "));
MessageBox.Show(a);//这里获取到了2次数据,循环。
result = new GuoJiPrice(a, b, c, d, now); }
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
return result;
}返回写入数据库方法的时候,只获取到了一次数据,默认第一条数据public static bool AddGuoJiPrice(int Id, int ClassId, GuoJiPrice guojiprices)//国际市场价格写入
{
try
{
MessageBox.Show(guojiprices.ZhongLiang);//这里只取到一次数据,也就是说跟没循环一样
string sql = string.Format("insert into GuoJiJiaGe(ClassId,SmallId,Addtime,...) values({1},{0},#{2}#,........)", ClassId, Id, guojiprices.AddTime,........);
OleDbCommand cmd = new OleDbCommand(sql, con);
return cmd.ExecuteNonQuery() > 0;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
写入数据库的方法: class GuoJiPrice
{
public string JiBie;
public string JiaoHuo;
public string JiaGe;
public string UpDown;
public string AddTime;
public GuoJiPrice(string JiBie_, string JiaoHuo_, string JiaGe_, string UpDown_,string AddTime_)
{
JiBie = JiBie_;
JiaoHuo = JiaoHuo_;
JiaGe = JiaGe_;
UpDown = UpDown_;
AddTime = AddTime_;
} }
搞了三天三夜了,找不出问题所在,求指点。
{
GuoJiPrice result = null;
try
{
string now = DateTime.Now.ToString("yyyy-MM-dd");
url = string.Format("{0}_{1}_{1}_1.htm", url, now);
string form = Http.GetHtml(url, ref cookie);
string form2 = Other.GetRegValue("<table width='100%' border='0' cellspacing='0' cellpadding='0' class='ProTab marginT'><tr((?!</table>).)+",form);
MatchCollection trmatches = Other.GetRegValues("<tr><td((?!</tr>).)+", form2);
foreach (Match match in trmatches)
{
MatchCollection matches = Other.GetRegValues("<td((?!</td>).)+", match.Value);
string a = Other.GetRegValue(@".*", matches[1].Value.Replace("<td align='center'> ", ""));
string b = Other.GetRegValue(@".*", matches[2].Value.Replace("<td align='center'> ", ""));
string c = Other.GetRegValue(@".*", matches[3].Value.Replace("<td align='center'> ", ""));
string d = Other.GetRegValue(@".*", matches[4].Value.Replace("<td><span class='down'>", " "));
MessageBox.Show(a);//这里获取到了2次数据,循环。
result = new GuoJiPrice(a, b, c, d, now); }
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
return result;
}返回写入数据库方法的时候,只获取到了一次数据,默认第一条数据public static bool AddGuoJiPrice(int Id, int ClassId, GuoJiPrice guojiprices)//国际市场价格写入
{
try
{
MessageBox.Show(guojiprices.ZhongLiang);//这里只取到一次数据,也就是说跟没循环一样
string sql = string.Format("insert into GuoJiJiaGe(ClassId,SmallId,Addtime,...) values({1},{0},#{2}#,........)", ClassId, Id, guojiprices.AddTime,........);
OleDbCommand cmd = new OleDbCommand(sql, con);
return cmd.ExecuteNonQuery() > 0;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
写入数据库的方法: class GuoJiPrice
{
public string JiBie;
public string JiaoHuo;
public string JiaGe;
public string UpDown;
public string AddTime;
public GuoJiPrice(string JiBie_, string JiaoHuo_, string JiaGe_, string UpDown_,string AddTime_)
{
JiBie = JiBie_;
JiaoHuo = JiaoHuo_;
JiaGe = JiaGe_;
UpDown = UpDown_;
AddTime = AddTime_;
} }
搞了三天三夜了,找不出问题所在,求指点。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货