日期:2014-05-17  浏览次数:20504 次

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

我对正则不熟悉,请各位赐教!

------解决方案--------------------
何必这么抓,很多webservice都支持返回各个城市天气预报的

------解决方案--------------------
正则比较好处理!
先看看教程吧,看2个小时就差不多了,不会的再去看。
这个比较简介
http://unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm
------解决方案--------------------
QQ群:323373
------解决方案--------------------
学习,帮顶
------解决方案--------------------
up
------解决方案--------------------
写了例子,你看看不知道有用没?

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);


}
}
}

------解决方案--------------------
找个webService..
或是用WebRequest.网上一搜一大把.