<!--day 1-->
<table class="yuBaoTable" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15%" rowspan="2" class="t0" style="background:#f4f7fc;"><a title="农历六月初一">1日星期五</a></td>
<td width="12%" style="background:#f4f7fc;">白天</td>
<td width="10%">
<a href="http://www.weather.com.cn/static/html/legend.shtml" target="_blank">
<img src="/m2/i/icon_weather/29x20/d00.gif" />
</a>
</td>
<td width="18%"><a href ="http://baike.weather.com.cn/index.php?doc-view-767.php" target="_blank">晴</a></td>
<td width="15%">
<a href="http://baike.weather.com.cn/index.php?doc-view-1148.php" target="_blank">
<b>高温 <strong>34<strong>℃</b>
</a>
</td>
<td width="15%">
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
无持续风向
</a>
</td>
<td width="15%">
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
微风
</a>
</td>
</tr>
<tr>
<td style="background:#f4f7fc;">夜间</td>
<td>
<a href="http://www.weather.com.cn/static/html/legend.shtml" target="_blank">
<img src="/m2/i/icon_weather/29x20/n01.gif" />
</a>
</td>
<td><a href ="http://baike.weather.com.cn/index.php?doc-view-769.php" target="_blank">多云</a></td>
<td>
<a href="http://baike.weather.com.cn/index.php?doc-view-1386.php" target="_blank">
<span>低温 <strong>26<strong>℃</span>
</a>
</td>
<td>
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
无持续风向
</a>
</td>
<td>
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
微风
</a>
</td>
</tr>
</table>
<!--day 2-->截取之间的内容放入一个string[]里面,我的方法public string[] htmlCrwal4(string htmlstr, string begstr, string endstr)
{
string temp = "";
int start, stop; // start = HTML.IndexOf("</style>", 0, HTML.Length);``
start = htmlstr.IndexOf(begstr, 0, htmlstr.Length); stop = htmlstr.IndexOf(endstr, 0, htmlstr.Length);
temp = htmlstr.Substring(start, stop - start);
Regex regex = new Regex("<[^>]*>");
string[] ss = regex.Split(temp);
string t = "";
foreach (string p in ss)
if (p.Trim().Length > 0)
t += p + "/";
string[] sss = t.Split('/'); return sss; }
htmlCrwal4(htmlstring,"<!--day 1-->","<!--day 2-->"), 但是就是不对,是什么地方错了呢,或者用正则表达式能解决也可以,请大家支招,感谢了。
<table class="yuBaoTable" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15%" rowspan="2" class="t0" style="background:#f4f7fc;"><a title="农历六月初一">1日星期五</a></td>
<td width="12%" style="background:#f4f7fc;">白天</td>
<td width="10%">
<a href="http://www.weather.com.cn/static/html/legend.shtml" target="_blank">
<img src="/m2/i/icon_weather/29x20/d00.gif" />
</a>
</td>
<td width="18%"><a href ="http://baike.weather.com.cn/index.php?doc-view-767.php" target="_blank">晴</a></td>
<td width="15%">
<a href="http://baike.weather.com.cn/index.php?doc-view-1148.php" target="_blank">
<b>高温 <strong>34<strong>℃</b>
</a>
</td>
<td width="15%">
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
无持续风向
</a>
</td>
<td width="15%">
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
微风
</a>
</td>
</tr>
<tr>
<td style="background:#f4f7fc;">夜间</td>
<td>
<a href="http://www.weather.com.cn/static/html/legend.shtml" target="_blank">
<img src="/m2/i/icon_weather/29x20/n01.gif" />
</a>
</td>
<td><a href ="http://baike.weather.com.cn/index.php?doc-view-769.php" target="_blank">多云</a></td>
<td>
<a href="http://baike.weather.com.cn/index.php?doc-view-1386.php" target="_blank">
<span>低温 <strong>26<strong>℃</span>
</a>
</td>
<td>
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
无持续风向
</a>
</td>
<td>
<a href="http://baike.weather.com.cn/index.php?doc-view-778.php" target="_blank">
微风
</a>
</td>
</tr>
</table>
<!--day 2-->截取之间的内容放入一个string[]里面,我的方法public string[] htmlCrwal4(string htmlstr, string begstr, string endstr)
{
string temp = "";
int start, stop; // start = HTML.IndexOf("</style>", 0, HTML.Length);``
start = htmlstr.IndexOf(begstr, 0, htmlstr.Length); stop = htmlstr.IndexOf(endstr, 0, htmlstr.Length);
temp = htmlstr.Substring(start, stop - start);
Regex regex = new Regex("<[^>]*>");
string[] ss = regex.Split(temp);
string t = "";
foreach (string p in ss)
if (p.Trim().Length > 0)
t += p + "/";
string[] sss = t.Split('/'); return sss; }
htmlCrwal4(htmlstring,"<!--day 1-->","<!--day 2-->"), 但是就是不对,是什么地方错了呢,或者用正则表达式能解决也可以,请大家支招,感谢了。
解决方案 »
- web.config如何配置域名转向
- 怎么使用 “最佳黑色背景的Visual Studio 2008配置”?
- 求真实的OA需求文档!
- 想实现打印条形码功能以及如何设置选中textbox的内容
- 关于引号的问题 急!!在线等 没分了,大家帮帮忙吧
- 郁闷的ACCESS问题,从没用过
- 一个关于缓存的奇怪问题
- aSP.NET 2.0 UrlRewriteRules 在Win2003 Server IIS上的重写问题
- SqlCommand.ExecuteNonQuery 调用存储过程不能返回受影响的行数?
- 如何直接打开第三方网站查询结果
- 初期构架失误,高手帮忙看看
- 用asp.net怎样对数据库进行 差异备份和增量备份。?
void Main()
{
string html = @"<!--day 1-->
<table class=""yuBaoTable"" width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">
<tr>
<td width=""15%"" rowspan=""2"" class=""t0"" style=""background:#f4f7fc;""><a title=""农历六月初一"">1日星期五</a></td>
<td width=""12%"" style=""background:#f4f7fc;"">白天</td>
<td width=""10%"">
<a href=""http://www.weather.com.cn/static/html/legend.shtml"" target=""_blank"">
<img src=""/m2/i/icon_weather/29x20/d00.gif"" />
</a>
</td>
<td width=""18%""><a href =""http://baike.weather.com.cn/index.php?doc-view-767.php"" target=""_blank"">晴</a></td>
<td width=""15%"">
<a href=""http://baike.weather.com.cn/index.php?doc-view-1148.php"" target=""_blank"">
<b>高温 <strong>34<strong>℃</b>
</a>
</td>
<td width=""15%"">
<a href=""http://baike.weather.com.cn/index.php?doc-view-778.php"" target=""_blank"">
无持续风向
</a>
</td>
<td width=""15%"">
<a href=""http://baike.weather.com.cn/index.php?doc-view-778.php"" target=""_blank"">
微风
</a>
</td>
</tr>
<tr>
<td style=""background:#f4f7fc;"">夜间</td>
<td>
<a href=""http://www.weather.com.cn/static/html/legend.shtml"" target=""_blank"">
<img src=""/m2/i/icon_weather/29x20/n01.gif"" />
</a>
</td>
<td><a href =""http://baike.weather.com.cn/index.php?doc-view-769.php"" target=""_blank"">多云</a></td>
<td>
<a href=""http://baike.weather.com.cn/index.php?doc-view-1386.php"" target=""_blank"">
<span>低温 <strong>26<strong>℃</span>
</a>
</td>
<td>
<a href=""http://baike.weather.com.cn/index.php?doc-view-778.php"" target=""_blank"">
无持续风向
</a>
</td>
<td>
<a href=""http://baike.weather.com.cn/index.php?doc-view-778.php"" target=""_blank"">
微风
</a>
</td>
</tr>
</table>
<!--day 2-->";
string[] result= Regex.Replace(html,"<[^>]*>","/").Split(new char[]{'/'},StringSplitOptions.RemoveEmptyEntries).Where(s=>!string.IsNullOrEmpty(s.Trim())).ToArray();
result.ToList().ForEach(s=>Console.WriteLine(s.Trim()));
/*
1日星期五
白天
晴
高温
34
℃
无持续风向
微风
夜间
多云
低温
26
℃
无持续风向
微风 */
}