抓取网页中的天气预报

purexiafeng 2007-12-06 11:29:37
就是这个网页上的http://www.worldweather.cn/ci/ci001.htm ,只抓天气预报(日期,最高,最低,天气情况),要用正则吗?

我对正则不熟悉,请各位赐教!
...全文
109 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveyi419 2012-06-25
  • 打赏
  • 举报
回复
抓取代码后怎么给代码中的控件赋值,还有怎么操作代码中的按钮事件啊
luyuanzhiwindows 2007-12-06
  • 打赏
  • 举报
回复
up
purexiafeng 2007-12-06
  • 打赏
  • 举报
回复
主要的是为了稳定,随便找个webservice调用,以后不提供了就要该东西了
glacier111 2007-12-06
  • 打赏
  • 举报
回复
学习,帮顶
Hsinbill 2007-12-06
  • 打赏
  • 举报
回复
QQ群:323373
kerryhe 2007-12-06
  • 打赏
  • 举报
回复
正则比较好处理!
先看看教程吧,看2个小时就差不多了,不会的再去看。
这个比较简介
http://unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm
shawn_yang 2007-12-06
  • 打赏
  • 举报
回复
何必这么抓,很多webservice都支持返回各个城市天气预报的
lovehongyun 2007-12-06
  • 打赏
  • 举报
回复
找个webService..
或是用WebRequest.网上一搜一大把.
joycepure18 2007-12-06
  • 打赏
  • 举报
回复
写了例子,你看看不知道有用没?

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace GetWeather
{
class Program
{
static void Main(string[] args)
{
string url = "http://www.worldweather.cn/ci/ci001.htm";

WebRequest wreq = WebRequest.Create(url);

HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();

string HTML = "";
Stream s = wresp.GetResponseStream();

StreamReader objReader = new StreamReader(s, System.Text.Encoding.Default);

string sLine = "";
int i = 0;

while (sLine != null)
{
i++;
sLine = objReader.ReadLine();
if (sLine != null)
HTML += sLine;
}

// System.Console.WriteLine(HTML);
string strIndex;
int sIndex, eIndex;
string min, max, temp;

strIndex = "<td width=\"70\" align=\"center\"><b><font color=#0000ff>";

sIndex = HTML.IndexOf(strIndex) + strIndex.Length;

strIndex = "</font></b></td>";

eIndex = HTML.IndexOf(strIndex, sIndex);

min = HTML.Substring(sIndex, eIndex - sIndex);

strIndex = "<td width=\"70\" align=\"center\"><b><font color=#ff3300>";

sIndex = HTML.IndexOf(strIndex) + strIndex.Length;

strIndex = "</font></b></td>";

eIndex = HTML.IndexOf(strIndex, sIndex);

max = HTML.Substring(sIndex, eIndex - sIndex);

strIndex = "<td><b>";

sIndex = HTML.IndexOf(strIndex) + strIndex.Length;

strIndex = "</b></td>";

eIndex = HTML.IndexOf(strIndex, sIndex);

temp = HTML.Substring(sIndex, eIndex - sIndex);


System.Console.WriteLine(min);
System.Console.WriteLine(max);
System.Console.WriteLine(temp);


}
}
}

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧