62,041
社区成员
发帖
与我相关
我的任务
分享
public GuoJiPrice GetGuoJiPriceInfo(string url)
{
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);//获取页面
form = Other.GetRegValue("<tr><td((?!</tr>).)+", form);//页面内容所在区域
MatchCollection matches = Other.GetRegValues("<td((?!</td>).)+", form);//要获取的内容
foreach (Match m in matches)
{
string a = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //获取第一个匹配到的内容
string b = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
string c = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
string d = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
return new GuoJiPrice(a, b, c, d, now);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
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,ZhongLiang,JiaGe,ChanDi,ZhangDie) 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;
}
}
public List<GuoJiPrice> GetGuoJiPriceInfo(string url)
{
List<GuoJiPrice> alllist=new List<GuoJiPrice>();
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);//获取页面
form = Other.GetRegValue("<tr><td((?!</tr>).)+", form);//页面内容所在区域
MatchCollection matches = Other.GetRegValues("<td((?!</td>).)+", form);//要获取的内容
foreach (Match m in matches)
{
string a = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //获取第一个匹配到的内容
string b = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
string c = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
string d = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
result= GuoJiPrice(a, b, c, d, now);
alllist.add(result);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
retrun alllist;
}
public GuoJiPrice GetGuoJiPriceInfo(string url)
{
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);
form = Other.GetRegValue("<tr><td((?!</tr>).)+", form);
MatchCollection matches = Other.GetRegValues("<td((?!</td>).)+", form);
string a = Other.GetRegValue(@".*", matches[1].Value);
string b = Other.GetRegValue(@".*", matches[2].Value);
string c = Other.GetRegValue(@".*", matches[3].Value);
string d = Other.GetRegValue(@".*", matches[4].Value);
return new GuoJiPrice(a, b, c, d, now);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
...
string a = string.Empty;
string b = string.Empty;
string c = string.Empty;
string d = string.Empty;
foreach (Match m in matches)
{
a = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //获取第一个匹配到的内容
b = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
c = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
d = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
}
return new GuoJiPrice(a, b, c, d, now);
...
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);//获取页面
form = Other.GetRegValue("<tr><td((?!</tr>).)+", form);//页面内容所在区域
MatchCollection matches = Other.GetRegValues("<td((?!</td>).)+", form);//要获取的内容
foreach (Match m in matches)
{
string a = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //获取第一个匹配到的内容
string b = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
string c = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
string d = m.Groups[@".*", matches[1].Value.Replace("<td align='center'> ", ""));].Value; //
result= GuoJiPrice(a, b, c, d, now);
break;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
result=null;
}
retrun result;
}