天气预报小偷
来源:互联网 发布:pg数据库与oracle区别 编辑:程序博客网 时间:2024/04/30 05:18
公司制作内部网站,需要有个天气预报功能,但是普通用户只能内部网而不能访问外网,只有专用AD帐户可以通过代理访问外网;
以下asp.net(c#) 通过代理获取google天气预报的代码,过程如下:
1. 通过代理获取google天气预报的HTML代码;
2. 通过分析,提取出需要的天气预报代码;
********************************
ASPX:
***中国省市县联动下拉菜单代码请自己添加 ***
<body leftmargin="2" topmargin="2" onload="Init();" >
<form id="form1" runat="server" >
<div>
<select id="Select1" name="Select1" runat="server" onchange="selectCity();">
<option value="" selected="true">省/直辖市</option>
</select>
<select id="Select2" name="Select2" runat="server" onchange="selectCountry()">
<option value="" selected="true">请选择</option>
</select>
<asp:DropDownList ID="Select3" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</div>-
<div align =left>
<table>
<tr>
<td align=leftl>
<asp:Label id="weathergoogle" runat="server">weathergoogle</asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
****************************************************************
CS:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml;
namespace forcast
{
public partial class weathergoole : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string domain = "";
string username = "";
string password = "";
string ip = "";
string port = "";
string virtualdirectory = "";
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("conf1q2w.xml"));
DataTable table = ds.Tables[0];
for (int index = 0; index < table.Rows.Count; index++)
{
domain = table.Rows[index]["domain"].ToString();
username = table.Rows[index]["username"].ToString();
password = table.Rows[index]["password"].ToString();
ip = table.Rows[index]["ip"].ToString();
port = table.Rows[index]["port"].ToString();
virtualdirectory = table.Rows[index]["virtualdirectory"].ToString(); ;
}
//以上通过读取xml获取代理的地址、端口、用户和密码。
string item1 = Select1.Items[Select1.SelectedIndex].Value;
//string item2 = Request.Form["Select2"];
string item3 = Request.Form["Select3"];
string defaultarea = "xiamen";
if (!string.IsNullOrEmpty(item3))
{
defaultarea = item3;
}
//以上为从ASPX页面获取县市名称;
WebProxy proxy = new WebProxy(ip, 8080);
proxy.Credentials = new NetworkCredential(username, password, domain);
proxy.BypassProxyOnLocal = true;
Uri forecastUrl = new Uri("http://www.google.cn/search?source=igchina&hl=zh-CN&rlz=1G1GGLQ_ZH-CNCN332&q=tq%2B"+defaultarea);
WebRequest wreq = WebRequest.Create(forecastUrl);
//goole天气地址http://www.google.cn/search?source=igchina&hl=zh-CN&rlz=1G1GGLQ_ZH-CNCN332&q=tq%2B"+defaultarea , defaultare为默认天气预报区域
wreq.Proxy = proxy;
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
Stream s = wresp.GetResponseStream();
StreamReader objReader = new StreamReader(s, System.Text.Encoding.Default);
string HTML = objReader.ReadToEnd();
string sLine = "";
int i = 0;
while (sLine != null)
{
i++;
sLine = objReader.ReadLine();
if (sLine != null)
HTML += sLine;
}
String temp = "";
int start, stop;
start = HTML.IndexOf("<div class=e><table class=/"ts std/">", 0, HTML.Length);
stop = HTML.IndexOf("</div></table></div>", 0, HTML.Length);
temp = HTML.Substring(start, stop - start);
temp = temp.Replace("Ìí¼Óµ½ iGoogle", "");
temp = temp.Replace(" - ", "");
temp = temp.Replace("font-size:140%","");
temp = temp.Replace("padding:5px", "padding:1px");
weathergoogle.Text = temp; //把天气预报代码显示到页面
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
3. 效果
- 天气预报小偷
- 天气预报小偷
- 天气预报的小偷程序
- tom天气预报小偷
- 小偷程序--火车票和天气预报
- XMLHTTP小偷程序原理-及一天气预报小偷程序
- PHP实例教程:天气预报小偷PHP代码
- 自己用HttpWebRequest写的一个天气预报小偷
- 自己用HttpWebRequest写的一个天气预报小偷
- [30期] PHP正则表达式写天气预报小偷程序
- [30期] PHP正则表达式写天气预报小偷程序
- [30期] PHP正则表达式写天气预报小偷程序
- 小偷
- 小偷
- 天气预报
- 天气预报
- 天气预报
- 天气预报
- DB2备份与恢复
- 好呀
- 你想学一门语言吗?
- 如何正确加mhash
- 朋友之情淡如水
- 天气预报小偷
- 干了活还受气该怎么办?(杜拉拉升职记)
- 您可能不知道的.Net2.0小技巧
- windows日志对应出错表
- 狮心王
- Misrosoft Enterprise Lib操作
- 一次DEBUG经历
- SQL SERVER 与ACCESS、EXCEL之间的数据转换
- 如何在asp.net中如何在线播放视频文件