如题:
c# winform 如何获得http://qq.ip138.com/weather/xinjiang/WuLuMuQi.htm这个网址中的天气预报

解决方案 »

  1.   

    把网页得到TOXML用XML取出来··
      

  2.   

    /// <summary> 
      /// 根据城市取得天气预报信息 
      /// </summary> 
      /// <param name="ps_CityName">城市中文名称 如:福州</param> 
      /// <returns></returns> 
      public static string GetSinaWether(string ps_CityName) 
      { 
       string strCity = StrConv(ps_CityName,"GB2312"); 
        
       //string myuri="http://appnews.qq.com/cgi-bin/news_qq_search?city="+city; 
       string myuri="http://weather.news.sina.com.cn/cgi-bin/figureWeather/simpleSearch.cgi?city="+strCity;    
       WebRequest webr=WebRequest.Create(myuri); 
           Stream rc=webr.GetResponse().GetResponseStream(); 
        
       StreamReader read=new StreamReader(rc,System.Text.Encoding.Default); 
       string abc=read.ReadToEnd(); 
       int l1=abc.IndexOf("今日天气"); 
       string restr="<font face=黑体 style=font-size:18px;>"+abc.Substring(l1).Replace("<br>","").Replace("<td style=","").Replace("class=l15>","").Replace("color:#083887","").Replace("</td>","").Replace("</tr>","").Replace("</table>","").Replace("</body>","").Replace("</html>",""); 
       return restr.Replace("50","20"); 
      }   /// <summary> 
      /// 根据城市取得天气预报信息 
      /// </summary> 
      /// <param name="ps_CityName">城市中文名称 如:福州</param> 
      /// <returns></returns> 
      public static string GetQQWether(string ps_CityName) 
      { 
       string strCity = StrConv(ps_CityName,"GB2312"); 
        
       string myuri="http://appnews.qq.com/cgi-bin/news_qq_search?city="+strCity; 
       WebRequest webr=WebRequest.Create(myuri); 
        
       Stream rc=webr.GetResponse().GetResponseStream(); 
        
       StreamReader read=new StreamReader(rc,System.Text.Encoding.Default); 
       string abc=read.ReadToEnd(); 
       return abc; 
      }   /// <summary> 
      /// 编码转换 
      /// </summary> 
      /// <param name="strIn"></param> 
      /// <param name="encoding"></param> 
      /// <returns></returns> 
      public static string StrConv(string strIn, string encoding) 
      { 
       return System.Web.HttpUtility.UrlEncode(strIn,System.Text.Encoding.GetEncoding(encoding)); 
      } 
      

  3.   

      public static string GetQQWether(string ps_CityName) 
      { 
      string strCity = StrConv(ps_CityName,"GB2312"); 
        
      string myuri="http://qq.ip138.com/weather/xinjiang/WuLuMuQi.htm; 
      WebRequest webr=WebRequest.Create(myuri); 
        
      Stream rc=webr.GetResponse().GetResponseStream(); 
        
      StreamReader read=new StreamReader(rc,System.Text.Encoding.Default); 
      string abc=read.ReadToEnd(); 
      return 
      

  4.   

    天气预报都有webservce,你只要在程序中引用一下就可以了。
      

  5.   


    使用WebService 访问多好!http://www.wopos.com/webservice/Weather.asmx
      

  6.   

    用WebSerice访问天气预报: [WebMethod]    public string GetWeather(string city)
        {
            string weacherhtml = string.Empty;
            //转换输入参数的编码类型
            string mycity = System.Web.HttpUtility.UrlEncode(city, System.Text.UnicodeEncoding.GetEncoding("GB2312"));
            //初始化新的 WebRequest
            HttpWebRequest webrt = (HttpWebRequest)WebRequest.Create("http://php.weather.sina.com.cn/search.php?city=" + mycity);
            HttpWebResponse webrs = (HttpWebResponse)webrt.GetResponse();
            //从Internet资源返回数据流 
            Stream stream = webrs.GetResponseStream();
            //读取数据流
            StreamReader srm = new StreamReader(stream, System.Text.Encoding.Default);
            //读取数据
            weacherhtml = srm.ReadToEnd();
            srm.Close();
            stream.Close();
            webrs.Close();
            //针对不同的网站,请查看HTML源文件
            int start = weacherhtml.IndexOf("天气状况 begin"); //取的字符位置
            int end = weacherhtml.IndexOf("天气状况 end");
            return weacherhtml.Substring(start + 14, end - start);
        }
      

  7.   

    学习了!!
    帮你顶!!
    天气预报有个webservice,你直接调用即可!!
      

  8.   

    我的怎么没有System.Web.HttpUtility这个
      

  9.   

    ericzhangbo1982111
    我能取出它的源文件。
    可是不知道怎么从源文件里读取。
    不知道用什么办法。
      

  10.   

    取得文件应该里面有这些东西
    可以用
            WebBrowser web = new WebBrowser();
                web.DocumentText = "";//取得的html text。
                HtmlElementCollection coll=web.Document.GetElementsByTagName("table");
                foreach (HtmlDocument d in coll)
                {
                    
                }<table width="700" borderColorDark="#ffffff" borderColorLight="#008000" border="1" cellspacing="0" cellpadding="1">
    <tr bgColor="#6699cc">
    <th width="12%" class="tdc1">日期</td>
    <th class="tdc1">2008年6月13日</td>
    <th class="tdc1">2008年06月14日</td>
    <th class="tdc1">2008年06月15日</td>
    <th class="tdc1">2008年06月16日</td>
    <th class="tdc1">2008年06月17日</td>
    </tr>
    <tr>
    <td align="center">天气</td>
    <td><img src="/image/b2.gif" alt="阴" /><img src="/image/b0.gif" alt="晴" /><br/>阴 - 晴</td>
    <td><img src="/image/b0.gif" alt="晴" /><br/>晴</td>
    <td><img src="/image/b0.gif" alt="晴" /><img src="/image/b1.gif" alt="多云" /><br/>晴 - 多云</td>
    <td><img src="/image/b2.gif" alt="阴" /><img src="/image/b3.gif" alt="阵雨" /><br/>阴 - 阵雨</td>
    <td><img src="/image/b1.gif" alt="多云" /><img src="/image/b7.gif" alt="小雨" /><br/>多云 - 小雨</td>
    </tr>
    <tr>
    <td align="center">气温</td>
    <td>28℃~17℃</td>
    <td>30℃~18℃</td>
    <td>32℃~19℃</td>
    <td>30℃~18℃</td>
    <td>28℃~18℃</td>
    </tr>
    <tr>
    <td align="center">风向</td>
    <td>微风</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
      

  11.   


          WindowsApplication2.com.wopos.www.Weather aa = 
          new WindowsApplication2.com.wopos.www.Weather();
          this.textBox2.Text = aa.getWeather("乌鲁木齐");
          aa.Dispose();我这样引用http://www.wopos.com/webservice/Weather.asmx 了这个
    可提示
    无权限访问,若要开通请Q 76445866 .System.NullReferenceException: 未将对象引用设置到对象的实例。
       在 Weather.getWeather(String mCity)
    是我程序又问题还是这个不是免费的?
      

  12.   

    ericzhangbo1982111
    十分感谢您。
    WebBrowser web = new WebBrowser(); 
                web.DocumentText = "";//取得的html text。 
                HtmlElementCollection coll=web.Document.GetElementsByTagName("table"); 
                foreach (HtmlDocument d in coll) 
                { 
                    
                } 
    这里如何取内容呢?我是初学者。谢谢你帮助。
      

  13.   

    WebBrowser web = new WebBrowser(); 
                web.DocumentText = "";//取得的html text。 
                HtmlElementCollection coll=web.Document.GetElementsByTagName("table"); 
                foreach (HtmlDocument d in coll) 
                { 
                    
                } 
    那么用这个方法如何获取呢?
      

  14.   

    这里好详细,基本上可以直接Copy代码:http://www.dotnetthink.com/?p=13