假设网页内有一张表格,如下分布:
年级 男生 女生
一年级 210 150
二年级 300 300
三年级 220 200
四年级 170 160
五年级 188 270
六年级 210 162现在我去抓数据,抓到男生>200人,同时在这一年级段,抓得女生<200,那么就将该年级数据提取出来,同时把男女生人数也提出来,最后制表结果为:
年级 男生 女生
一年级 210 150
六年级 210 162
请问:这样的程序应该怎么写?怎么下手,思路又怎样,谢谢了...0.0
年级 男生 女生
一年级 210 150
二年级 300 300
三年级 220 200
四年级 170 160
五年级 188 270
六年级 210 162现在我去抓数据,抓到男生>200人,同时在这一年级段,抓得女生<200,那么就将该年级数据提取出来,同时把男女生人数也提出来,最后制表结果为:
年级 男生 女生
一年级 210 150
六年级 210 162
请问:这样的程序应该怎么写?怎么下手,思路又怎样,谢谢了...0.0
Response.Write("alert('HELP');");
//创建DataTable
DataTable workTable = new DataTable();
workTable.Columns.Add("Grade", typeof(String));
workTable.Columns.Add("BoysCount", typeof(Int32));
workTable.Columns.Add("GrilsCount", typeof(Int32));
//然后遍历抓取每行数据,生成DataRow,插入DataTablea中
DataRow row = workTable.NewRow();
row["Grade"] = 年级;
row["BoysCount"] = 男生个数;
row["GrilsCount"] = 女生个数;
workTable.Rows.Add(row);
//查询满足条件的年级
DataRows[] rows = workTable.Select("BoysCount>200 And GrilsCount<200");
//遍历得到的行,写入新的HTML表格中
foreach(DataRow pRow in rows)
{
年级=row["Grade"].ToString();
男生个数=Int32.Parse(row["BoysCount"]);
女生个数=Int32.Parse(row["GrilsCount"]);
//写入HTML表格行中
}
string text = File.getAllline("aa.html");
int head = text.find("<table>")
int tail = text.find("</table>")
string table = text.substring(head,tail);
这样就获取table了
<table>
<tr>
<td></td>
<tr>
<tr>
<td></td>
<tr>
</table>
然后把table 保存在xmldocument 对象中 用xml分析就可以了
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";
System.Net.WebResponse response = request.GetResponse();
System.IO.Stream resStream = response.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resStream, encoding);
string html = (sr.ReadToEnd());
resStream.Close();http://topic.csdn.net/u/20090819/10/8b3d325c-5c9e-4e17-b344-a26f13e20aba.html?seed=2057216004&r=59199023
http://blog.csdn.net/Radar2006/archive/2006/12/30/1469328.aspx
...{
//取得网页代码
string str=GetWebContent("http://www.zhcw.com/lottery/3d_index.htm");
//MessageBox.Show(str); //提取信息
string regexStr=@"<tr>s*<tds*[^>]*>s*<span[^>]*>([^<]*)</span>s*</td>s*<td[^>]*>s*<span[^>]*>([^<]*)</span>s*</td>s*<td[^>]*>s*<table[^>]*>s*<tr[^>]*>(s*<td[^>]*>(d)</td>)+s*</tr>s*</table>s*</td>(s*<td[^>]*>(s*<span[^>]*>)?([^<]*)(</span>)?</td>)+";
Regex re=new Regex(regexStr,RegexOptions.IgnoreCase|RegexOptions.Singleline|RegexOptions.IgnorePatternWhitespace);
MatchCollection mc=re.Matches(str); //是否有新的开奖数据
if(mc.Count==0)
...{
MessageBox.Show("抱歉,没有新的开奖数据!");
return;
} //数据文件是否已存在,如存在则更新
if(System.IO.File.Exists(".\lottery.xml")==false)
...{
MessageBox.Show("请先下载开奖数据!");
return;
}
DataSet ds=new DataSet();
ds.ReadXml(".\lottery.xml",System.Data.XmlReadMode.ReadSchema); DataTable dt=ds.Tables[0];
dt.DefaultView.Sort="期号 desc"; int maxQh=Int32.Parse(dt.DefaultView[0].Row["期号"].ToString()); DataRow dr=null;
foreach(Match m in mc)
...{
int nQh=Int32.Parse(m.Groups[2].Value);
if(nQh>maxQh)
...{
dr=dt.NewRow();
dr["开奖日期"]=m.Groups[1].Value;
dr["期号"]=m.Groups[2].Value;
dr["中奖号码"]=m.Groups[4].Captures[0].Value + " "
+ m.Groups[4].Captures[1].Value + " "
+ m.Groups[4].Captures[2].Value;
dr["销售额"]=m.Groups[7].Captures[3].Value;
dr["单选"]=m.Groups[7].Captures[0].Value;
dr["组选3"]=m.Groups[7].Captures[1].Value;
dr["组选6"]=m.Groups[7].Captures[2].Value;
dt.Rows.Add(dr);
}
}
ds.WriteXml(".\lottery.xml",System.Data.XmlWriteMode.WriteSchema);
MessageBox.Show("恭喜,开奖结果更新成功!");
}