通过HttpWebRequest对象和HttpWebResponse对象从网页获取信息的一个实例,有兴趣的朋友可以看看。代码如下:
效果图:
如果想在网页中实现类似的功能,有更简单的方法,只需调用下面这段脚本即可,而且其返回的结果为一张图片,效果更好。
效果图:
static
string GetWeatherInfo(
string s1,
string s2)
{
string ResponseText;
string text;
int startIndex;
int endIndex;
Uri url =
new Uri(
@"http://firetear.com/weather/lvweather.aspx");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
req.Method = "Post";
StreamReader ReaderText = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
ResponseText = ReaderText.ReadToEnd();
res.Close();
startIndex = ResponseText.IndexOf(s1) + s1.Length;
endIndex = ResponseText.IndexOf(s2);
text = ResponseText.Substring(startIndex, endIndex - startIndex);
return text;
}
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
private void Form1_Load(object sender, EventArgs e)
{
Label1.Text = GetWeatherInfo(@"g>", @"</");
Label2.Text = GetWeatherInfo(@"天气:", @",紫");
}
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
private void Form1_Load(object sender, EventArgs e)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
效果图:
![](../p_w_upload/200801/200801041199440734319.jpg)
如果想在网页中实现类似的功能,有更简单的方法,只需调用下面这段脚本即可,而且其返回的结果为一张图片,效果更好。
<
img
src
="http://firetear.com/weather/weather.aspx"
border
="0"
alt
="查询及定制我的天气预报信息"
border
="0"
/>
效果图:
![](../p_w_upload/200801/200801041199440993819.png)
转载于:https://blog.51cto.com/ssbird/57986