zoukankan
html css js c++ java
从中央气象台抓取天气预报
这几天郑州下雪,一直盼望晴天的到来,于是关注天气情况.
可以Google一下:tq 郑州
如今写了个抓取中央气象台的天气预报(
http://www.tq121.com
)
public
string
GetWeather(
string
url)
{
string
weacherhtml
=
String.Empty;
HttpWebRequest rt
=
null
;
HttpWebResponse rs
=
null
;
Stream stream
=
null
;
StreamReader sr
=
null
;
try
{
rt
=
(HttpWebRequest)WebRequest.Create(url);
rs
=
(HttpWebResponse)rt.GetResponse();
stream
=
rs.GetResponseStream();
sr
=
new
StreamReader(stream,System.Text.Encoding.Default);
weacherhtml
=
sr.ReadToEnd();
}
catch
(Exception ee)
{
Response.Write(
"
<script>alert('发生异常')</script>
"
);
}
finally
{
sr.Close();
stream.Close();
rs.Close();
}
int
start
=
weacherhtml.IndexOf(
"
郑州
"
);
int
end
=
weacherhtml.IndexOf(
"
隐私保护
"
);
return
weacherhtml.Substring(start,end
-
start);
}
别的城市天气情况请调用相应的URL,以及修改城市名称.
查看全文
相关阅读:
游泳池 (Standard IO)
Antimonotonicity (Standard IO)
开花 (Standard IO)
Wild Number (Standard IO)
数码问题 (Standard IO)
输油管道 (Standard IO)
猴子摘桃 (Standard IO)
二叉树 (Standard IO)
iis运行asp.net页面提示“服务器应用程序不可用”的解决办法_.NET.
SVN安装配置与使用
原文地址:https://www.cnblogs.com/caca/p/81491.html
最新文章
SSH 远程登陆
我遇到的优秀年轻人都有哪些特质
vim常用快捷键
Linux curl命令详解
Linux中apt与apt-get命令的区别与解释
Python中read()、readline()和readlines()三者间的区别和用法
Python pickle使用
码工进阶能力修炼
POJ 1948 Triangular Pastures【二维01背包】
Codeforces Round #278 (Div. 2)
热门文章
POJ 1837 Balance 【DP】
UVa 1586 Molar mass
UVa 1225 Digit Counting
Codeforces Round #293 (Div. 2)
UVa 10935 Throwing cards away I【队列】
UVa 101 The Blocks Problem
POJ 1976 A Mini Locomotive【DP】
UVa 400 Unix Is
积木游戏 (Standard IO)
最小最大和 (Standard IO)
Copyright © 2011-2022 走看看