天气小偷程序,自动采集信息入库
来源:互联网 发布:清理僵尸粉软件 编辑:程序博客网 时间:2024/05/01 21:49
天气小偷程序 刚完成的一个天气小偷程序,从中央气象台自动采集信息入库 工程下载/************************************************/ using System.Text; using System.Net; using System.IO; using System.Text.RegularExpressions; using MSXML2; using System.Xml; public partial class userControls_weather : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string id = DropDownList1.SelectedValue; string city = DropDownList1.SelectedItem.Text; /***********************直接从雅虎网站偷取数据*************************************************************/ string Url = "http://weather.tq121.com.cn/detail.php?city /**************************************************************** WebRequest myWebRequest = WebRequest.Create(Url); WebResponse myWebResponse = myWebRequest.GetResponse(); System.IO.Stream stream = myWebResponse.GetResponseStream(); StreamReader sr = new StreamReader(stream, Encoding.Default); //以字符串形式读取数据流 string respstr = sr.ReadToEnd(); sr.Close(); Response.Write(respstr); ****************************************************************/ MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass(); _xmlhttp.open("GET", Url, true, null, null); _xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=gb2312"); _xmlhttp.send(null); if (_xmlhttp.readyState == 4) { //匹配日期,最高温,最低温 string patter = @"(?<=span class=""big-cn"">)[^℃]*?(?=/</span)|(?<=img src="").*?[a|b]{1}[0-9]{1,2}.gif(?=/"")|(?<=<span class=""big-cn"">|<span class=""wendu"">).*?(?=/</span)|(?<=span class=""cn"">)[/S]+(?=/</span)"; //匹配日期,最高温,最低温,天气图标 //string patter = @"(?<=th>).*?(?=/</th)|(?<=gr/).*?png(?=/))|(?<=High:).*?(?=/</strong)|(?<=Low:).*?(?=/</span)"; string str = Encoding.Default.GetString((byte[])_xmlhttp.responseBody); //Response.Write(str); return; str = Regex.Replace(str, @"(?<=span class=""big-cn"">)^预.*(?=/</span>)", ""); MatchCollection maction = Regex.Matches(str, patter); int j = 1; int n = 2; int k = 4; int m = 5; for (int i = 0; i < 5; i++) { //Response.Write(maction[i+1].Value + "<br />"); //Response.Write(maction[i+4].Value + "<br />"); string strSql = "insert into go_weather(submit_date,weather_city,weather_date,weather_img,weather_minTemp,weather_maxTemp,weather_wind) values(@subTime,@city,@date,@img,@min,@max,@wind)"; //string strSql = "insert into go_weather(submit_date,weather_city,weather_date,weather_minTemp,weather_maxTemp,weather_wind) values(" + DateTime.Today + "," + city + "," + maction[i + j].Value + "," + maction[i + k].Value + "," + maction[i + k].Value + "," + maction[i + m].Value + ")"; SqlParameter[] parms = { new SqlParameter("@subTime",SqlDbType.VarChar,16), new SqlParameter("@city",SqlDbType.VarChar,20), new SqlParameter("@date",SqlDbType.VarChar,20), new SqlParameter("@img",SqlDbType.VarChar,30), new SqlParameter("@min",SqlDbType.VarChar,20), new SqlParameter("@max",SqlDbType.VarChar,20), new SqlParameter("@wind",SqlDbType.VarChar,50)}; parms[0].Value = DateTime.Today; parms[1].Value = city; parms[2].Value = maction[i + j].Value; parms[3].Value = maction[i + n].Value.Replace("../images","../images/weather"); parms[4].Value = maction[i + k].Value; parms[5].Value = maction[i + k].Value; parms[6].Value = maction[i + m].Value; Response.Write(strSql+"<br />"); int val = go1000.SQLDBConnection.ExecuteNonQuery(CommandType.Text, strSql, parms); j += 4; n += 4; k += 4; m += 4; if (val > 0) Response.Write("<script>alert('aok;);</script>"); else Response.Write("<script>alert('error;);</script>"); } //return; } else { Response.Write("发生错误"); } } } |
- 天气小偷程序,自动采集信息入库
- 小偷程序和采集入库
- ASP小偷自动采集入库方法
- ASP小偷自动采集入库方法
- 浅谈自动采集程序及入库
- 浅谈自动采集程序及入库
- 浅谈自动采集程序及入库
- 浅谈自动采集程序及入库
- 浅谈自动采集程序及入库
- 自动采集程序及入库教程
- 浅谈ASP程序实现自动采集程序及入库
- 关于ASP程序实现自动采集程序及入库
- 数据采集程序(网页小偷)
- 采集/小偷程序核心功能
- PHP内容采集器(PHP小偷程序)
- 数据采集程序(网页小偷)点滴心得
- 数据采集程序(网页小偷)点滴心得
- 数据采集程序(网页小偷)点滴心得
- 继承和聚合
- web 工作流设计器
- 在RH9.0+vmware 5.xx上从开始到最后实现spca5xx驱动的安装 以及 嵌入式板上的驱动移植
- 新浪QQ等站天气预报代码调用大全zz
- 六年开发路,今天从头来
- 天气小偷程序,自动采集信息入库
- 归并排序和求逆序数对
- C++中的内存对齐
- Sql server 中Union 与 Case
- Cftea.WebControls.Countdown
- Nokia官方培训(Symbian 4300)笔记(一)--Forum Nokia
- 《Countdown控件(v1.0)用户手册》HTML 版
- Virtools中获取方向角度的方法(Get Orientation)。
- Cftea.WebControls.Countdown 二十四节气事件包