被抓取的页面代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>N A C A O 欢 迎 您</title>
<link rel="stylesheet" href="/css/f1.css" type="text/css"><script Language="javascript">
function Click(){
alert('禁用!');
window.event.returnValue=false;
}
document.oncontextmenu=Click;
</script></head>
<body leftmargin="0" topmargin="20" marginwidth="0" marginheight="0" onselectstart="return false">
<p><br></p>
<table cellspacing="0" cellpadding="0" width="778" align="center" class="nacao" border="0">
<tr>
<td colspan="3" align="center" valign=top>
</td>
</tr>
<tr valign="middle" >
<td width="14" height="27" align=left valign="top" background="/images/corner_top1.gif" ><img src="/images/corner_topleft1.gif" width="14" height="27"></td>
<td width="745" height="27" align=right valign="top" background="/images/corner_top1.gif" ><img src="/images/corner_toptu1.gif" width="98" height="27"></td>
<td width="19" height="27" align=right valign="top" background="/images/corner_top1.gif" ><img src="/images/corner_topright1.gif" width="19" height="27"></td>
</tr>
<tr valign="middle" >
<td height="83" align=left valign="top" background="/images/corner_left1.gif" > </td>
<td align=center valign="top" bgcolor="#EFF7FF" >
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" colspan="2" align="center" class="nacao"><font color="#FF0000">详细信息</font>
</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width="100%" align=center class="nacao" border=1>
<tr>
<td height="18" width="20%" align="right" class="nacao"><font color="#0000FF">机构代码: </font></td>
<td height="18" width="80%" align="left" class="nacao" colspan="3">
700360787
</td>
</tr>
<tr>
<td height="18" width="20%" align="right" class="nacao"><font color="#0000FF">机构名称: </font></td>
<td height="18" width="80%" align="left" class="nacao" colspan="3">
北京上海人家餐饮有限责任公司
</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width="100%" align=center class="nacao" border=0>
<tr>
<td height="40" colspan="1" align="center" valign="middle" class="nacao">
<input name="Submit" type="submit" class="nacao" value="关闭窗口" onClick="window.close()">
</td>
</tr>
</table>
</td>
<td align=right valign="top" background="../images/corner_right1.gif" ></td>
</tr>
<tr valign="middle" >
<td align=left valign="top" ><img src="../images/corner_bottomleft1.gif" width="14" height="30"></td>
<td align=middle background="../images/corner_bottomtu1.gif" ></td>
<td align=right valign="top" ><img src="../images/corner_bottomright1.gif" width="19" height="30"></td>
</tr> <font color="#3399CC">
</table>
</font>
</body>
</html>xml模板:
<?xml version="1.0" encoding="utf-8" ?>
<Analyst>
<![CDATA[<font color="#0000FF">机构代码: </font>
</td>
<td height="19" bgcolor="#F0F0F0">(?<Code>.*)</td>
</tr>
<tr>
<td height="18" width="20%" align="right" class="nacao"><font color="#0000FF">机构名称: </font></td>
<td height="18" width="80%" align="left" class="nacao" colspan="3">
(?<Corpname>.*)td>]]>
</Analyst>后台代码:
XmlDocument analystXmlDoc = new XmlDocument();
analystXmlDoc.Load(analystXmlPath);
string pattern = analystXmlDoc.DocumentElement.InnerText;// string strRegex = @"\?<(?<group>[\w]+)>";// MatchCollection matches = Regex.Matches(pattern,strRegex,RegexOptions.IgnoreCase| RegexOptions.Singleline | RegexOptions.Compiled);
MatchCollection matches = Regex.Matches(pageString,pattern,RegexOptions.IgnoreCase| RegexOptions.Singleline | RegexOptions.Compiled); string[] rtnString = new string[matches.Count]; for(int i=0;i<matches.Count;i++)
{
rtnString[i] = matches[i].Value;
}
提问:
我得到的rtnString 值为空的,请问为什么啊?请高手帮忙。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>N A C A O 欢 迎 您</title>
<link rel="stylesheet" href="/css/f1.css" type="text/css"><script Language="javascript">
function Click(){
alert('禁用!');
window.event.returnValue=false;
}
document.oncontextmenu=Click;
</script></head>
<body leftmargin="0" topmargin="20" marginwidth="0" marginheight="0" onselectstart="return false">
<p><br></p>
<table cellspacing="0" cellpadding="0" width="778" align="center" class="nacao" border="0">
<tr>
<td colspan="3" align="center" valign=top>
</td>
</tr>
<tr valign="middle" >
<td width="14" height="27" align=left valign="top" background="/images/corner_top1.gif" ><img src="/images/corner_topleft1.gif" width="14" height="27"></td>
<td width="745" height="27" align=right valign="top" background="/images/corner_top1.gif" ><img src="/images/corner_toptu1.gif" width="98" height="27"></td>
<td width="19" height="27" align=right valign="top" background="/images/corner_top1.gif" ><img src="/images/corner_topright1.gif" width="19" height="27"></td>
</tr>
<tr valign="middle" >
<td height="83" align=left valign="top" background="/images/corner_left1.gif" > </td>
<td align=center valign="top" bgcolor="#EFF7FF" >
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" colspan="2" align="center" class="nacao"><font color="#FF0000">详细信息</font>
</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width="100%" align=center class="nacao" border=1>
<tr>
<td height="18" width="20%" align="right" class="nacao"><font color="#0000FF">机构代码: </font></td>
<td height="18" width="80%" align="left" class="nacao" colspan="3">
700360787
</td>
</tr>
<tr>
<td height="18" width="20%" align="right" class="nacao"><font color="#0000FF">机构名称: </font></td>
<td height="18" width="80%" align="left" class="nacao" colspan="3">
北京上海人家餐饮有限责任公司
</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width="100%" align=center class="nacao" border=0>
<tr>
<td height="40" colspan="1" align="center" valign="middle" class="nacao">
<input name="Submit" type="submit" class="nacao" value="关闭窗口" onClick="window.close()">
</td>
</tr>
</table>
</td>
<td align=right valign="top" background="../images/corner_right1.gif" ></td>
</tr>
<tr valign="middle" >
<td align=left valign="top" ><img src="../images/corner_bottomleft1.gif" width="14" height="30"></td>
<td align=middle background="../images/corner_bottomtu1.gif" ></td>
<td align=right valign="top" ><img src="../images/corner_bottomright1.gif" width="19" height="30"></td>
</tr> <font color="#3399CC">
</table>
</font>
</body>
</html>xml模板:
<?xml version="1.0" encoding="utf-8" ?>
<Analyst>
<![CDATA[<font color="#0000FF">机构代码: </font>
</td>
<td height="19" bgcolor="#F0F0F0">(?<Code>.*)</td>
</tr>
<tr>
<td height="18" width="20%" align="right" class="nacao"><font color="#0000FF">机构名称: </font></td>
<td height="18" width="80%" align="left" class="nacao" colspan="3">
(?<Corpname>.*)td>]]>
</Analyst>后台代码:
XmlDocument analystXmlDoc = new XmlDocument();
analystXmlDoc.Load(analystXmlPath);
string pattern = analystXmlDoc.DocumentElement.InnerText;// string strRegex = @"\?<(?<group>[\w]+)>";// MatchCollection matches = Regex.Matches(pattern,strRegex,RegexOptions.IgnoreCase| RegexOptions.Singleline | RegexOptions.Compiled);
MatchCollection matches = Regex.Matches(pageString,pattern,RegexOptions.IgnoreCase| RegexOptions.Singleline | RegexOptions.Compiled); string[] rtnString = new string[matches.Count]; for(int i=0;i<matches.Count;i++)
{
rtnString[i] = matches[i].Value;
}
提问:
我得到的rtnString 值为空的,请问为什么啊?请高手帮忙。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货