网页源码:
<tr>
<td valign="top"><table width="743" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="743" height="38" background="pic/z10.jpg"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr>
<td height="30" align="left"><font color="555555" size="2"><strong>游戏区域</strong></font></td>
<td width="134" align="right"><font color="555555" size="2"><strong>目前价格</strong></font></td>
<td width="132" align="right"><font color="555555" size="2"><strong>收购量</strong></font></td>
<td width="80" align="center"><font color="555555" size="2"><strong>状态</strong></font></td>
<td width="58" align="center"><font color="555555" size="2"><strong>操作</strong></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="500" valign="top" background="pic/z12.jpg" align="center">
<table cellpadding="0" cellspacing="0" border="0" width="95%" align="center">
<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
Aegwynn US-Alliance //需提取
</td>
<td width="134" align="right">
0.88
元/ //需提取
Gold
</td>
<td width="132" align="right"><font color="535353">
0 //需提取
</font></td>
<td width="80" align="center"><font color="535353">
满仓 //需提取
</font></td>
<td width="58" height="25" align="center">
</td>
</tr>
</table>
</td></tr>
<tr><td>
<img src="pic/line1.jpg" width="100%" height="1" alt="" /></td>
</tr>
<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
Aegwynn US-Horde
</td>
<td width="134" align="right">
0.94
元/
Gold
</td>
<td width="132" align="right"><font color="535353">
0</font></td>
<td width="80" align="center"><font color="535353">
满仓
</font></td>
<td width="58" height="25" align="center">
</td>
</tr>
</table>
</td></tr>
<tr><td>
<img src="pic/line1.jpg" width="100%" height="1" alt="" /></td>
</tr>
网页格式:
游戏区域 目前价格 收购量 状态 操作
Aegwynn US-Alliance 0.88 元/ Gold 0 满仓
Aegwynn US-Horde 0.94 元/ Gold 0 满仓
Aerie'peak US-Alliance 0.94 元/ Gold 0 满仓
Aerie'peak US-Horde 0.99 元/ Gold 0 满仓
Agamaggan US-Alliance 0.82 元/ Gold 0 满仓
请问提取:游戏区域 ,目前价格 ,收购量 ,状态 的正则表达式.
<tr>
<td valign="top"><table width="743" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="743" height="38" background="pic/z10.jpg"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr>
<td height="30" align="left"><font color="555555" size="2"><strong>游戏区域</strong></font></td>
<td width="134" align="right"><font color="555555" size="2"><strong>目前价格</strong></font></td>
<td width="132" align="right"><font color="555555" size="2"><strong>收购量</strong></font></td>
<td width="80" align="center"><font color="555555" size="2"><strong>状态</strong></font></td>
<td width="58" align="center"><font color="555555" size="2"><strong>操作</strong></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="500" valign="top" background="pic/z12.jpg" align="center">
<table cellpadding="0" cellspacing="0" border="0" width="95%" align="center">
<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
Aegwynn US-Alliance //需提取
</td>
<td width="134" align="right">
0.88
元/ //需提取
Gold
</td>
<td width="132" align="right"><font color="535353">
0 //需提取
</font></td>
<td width="80" align="center"><font color="535353">
满仓 //需提取
</font></td>
<td width="58" height="25" align="center">
</td>
</tr>
</table>
</td></tr>
<tr><td>
<img src="pic/line1.jpg" width="100%" height="1" alt="" /></td>
</tr>
<tr>
<td align="left">
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0" class="unnamed1">
<tr align="left">
<td >
Aegwynn US-Horde
</td>
<td width="134" align="right">
0.94
元/
Gold
</td>
<td width="132" align="right"><font color="535353">
0</font></td>
<td width="80" align="center"><font color="535353">
满仓
</font></td>
<td width="58" height="25" align="center">
</td>
</tr>
</table>
</td></tr>
<tr><td>
<img src="pic/line1.jpg" width="100%" height="1" alt="" /></td>
</tr>
网页格式:
游戏区域 目前价格 收购量 状态 操作
Aegwynn US-Alliance 0.88 元/ Gold 0 满仓
Aegwynn US-Horde 0.94 元/ Gold 0 满仓
Aerie'peak US-Alliance 0.94 元/ Gold 0 满仓
Aerie'peak US-Horde 0.99 元/ Gold 0 满仓
Agamaggan US-Alliance 0.82 元/ Gold 0 满仓
请问提取:游戏区域 ,目前价格 ,收购量 ,状态 的正则表达式.
解决方案 »
- 这样的两个字符串不一样吗?
- C# 实现FTP
- socket监听 到 soap 包?
- 我的VS2008的新建项目里没有“安装和部署项目”?
- 请帮忙修改一段用存储过程查询的DataGrid代码
- 数组,不重复复制的随机问题!
- 我用C#编写的程序,在别的电脑上用不了,怎么办啊?
- Oracle数据库里NUMBER(12,4)这样的字段在C#里用什么来对应啊?
- C++中的 BYTE* pBuf = new BYTE[32 * 1024]; 转成C# 代码怎么转?
- 解决了给300分。关于web提交value="查询"的问题
- gridview 导出成Excel 中文问题
- c#中可以做像MMC那像的界面吗?
MatchCollection mc = Regex.Matches(yourStr, @"<table[^>]*?>\s+<tr[^>]*?>\s+<td[^>]*?>(?<area>[^<]*?)</td>\s+<td[^>]*?>(?<price>[^<]*?)</td>\s+<td[^>]*?><font[^>]*?>(?<num>[^<]*?)</font></td>\s+<td[^>]*?><font[^>]*?>(?<state>[^<]*?)</font></td>", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["area"].Value + "\n"; //游戏区域
richTextBox2.Text += m.Groups["price"].Value + "\n"; //目前价格
richTextBox2.Text += m.Groups["num"].Value + "\n"; //收购量
richTextBox2.Text += m.Groups["state"].Value + "\n"; //状态
}
你看从<tr align="left"> 这里开始匹配是不是也可以啊
还想问问.
我把结果连接成这么一个字符串后
temp = temp + m.Groups["area"].Value + " " + m.Groups["price"].Value + " " + m.Groups["num"].Value +" "+m.Groups["state"].Value怎么把这些数据分别写入数据库.或者不这样连接,能提供点意见.谢谢
(?<=[\>])+[^\>\<]+(?=[\<])
這樣也可以阿
我测试了一下,
结果:448个
第一个用了26.08秒
第二个用了25.67秒
等测试一下chinnel() 兄的
还想请问一下你们,把这些数据写入数据库是怎样的?用数据集?还是怎么?
如果想抓取完再一起处理,可以分别存数组,全部抓取完成后,for循环写数据库
另外如果数据量比较大,存在效率问题时,可以在后面加个 RegexOptions.Compiled参数,这样再测试下
MatchCollection mc = Regex.Matches(yourStr, @"<td[^>]*?>(?<area>[^<]*?)</td>\s+<td[^>]*?>(?<price>[^<]*?)</td>\s+<td[^>]*?><font[^>]*?>(?<num>[^<]*?)</font></td>\s+<td[^>]*?><font[^>]*?>(?<state>[^<]*?)</font></td>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
这次主要做几十个这样的网页的采集.打算分别写正则表达式.存在数据库中,然后定时采集.