现在打算做一个天气预报的程序
程序抓取国家气象台的网站内容
url如下下
http://www.cma.gov.cn/netcenter_news/qxyb/city/index.php?city=北京
//////////////////////////////////////////////////////////////////////////
public string GetSource(string url)
{
string source="";
try
{
WebRequest WReq=WebRequest.Create(url);
WebResponse WResp=WReq.GetResponse();
//get Stream
StreamReader sr=new StreamReader(WResp.GetResponseStream(),System.Text.Encoding.GetEncoding("gb2312"));
string strTemp="";
while((strTemp=sr.ReadLine())!=null)
{
source+=strTemp+"\r\n";
}
sr.Close();
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK);
}
return source;
}但抓取到里面没有ie里面看到的气象数据,不知道为神魔,谁要好的办法!!!

解决方案 »

  1.   

    我把你程序完整了一下,能取出html来呀using System;
    using System.Net;
    using System.IO;namespace UrlCatcher
    {
    class UrlCatcher
    {
    public string GetSource(string url)
    {
    string source="";
    try
    {
    WebRequest WReq=WebRequest.Create(url);
    WebResponse WResp=WReq.GetResponse();
    StreamReader sr=new StreamReader(WResp.GetResponseStream(),System.Text.Encoding.GetEncoding("gb2312"));
    string strTemp="";
    while((strTemp=sr.ReadLine())!=null)
    {
    source+=strTemp+"\r\n";
    }
    sr.Close();
    }
    catch(System.Exception ex)
    {
    Console.WriteLine ( ex.Message );
    }
    return source;
    } static void Main(string[] args)
    {
    UrlCatcher urlCatcher = new UrlCatcher();
    Console.WriteLine ( urlCatcher.GetSource ( @"http://www.cma.gov.cn/netcenter_news/qxyb/city/index.php?city=北京" ) );
    }
    }
    }
      

  2.   

    FT,我知道你什么意思了,你取出的是html代码,你要是想取天气信息得在去html代码里提取
      

  3.   

    也许是我没解释清楚,我通过C#是可以获取url的源码,但程序获得源码数据和IE中的不一样,重要的气象数据都没有! 而用Flashget下载http://www.cma.gov.cn/netcenter_news/qxyb/city/index.php?city=北京
    就可以得到 是不是我程序那里出了问题???????
    需要用纯Socket去撰写!!!
      

  4.   

    我的程序只能获取
    http://www.cma.gov.cn/netcenter_news/qxyb/city/index.php
    但不能获取
    http://www.cma.gov.cn/netcenter_news/qxyb/city/index.php?city=北京
    也就是对?后面查询不起作用
    我不知道C#对于Http协议中url字符串中含有 ?city=北京&area=华北 的如何处理???????
      

  5.   

    你掉了一个条件?city=北京&province=北京&area=华北中间的province=北京
      

  6.   

    Server.UrlEncode(base.Request.RawUrl))