读出天气信息

nply2008 2009-05-14 02:55:16
怎么在别人的网站里读出这里的天气信息
...全文
145 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2009-05-14
  • 打赏
  • 举报
回复
获取天气信息,再用正则格式化
参考
参考
xuStanly 2009-05-14
  • 打赏
  • 举报
回复
根据源代码的特点去构建正则,自然提得出来。
nply2008 2009-05-14
  • 打赏
  • 举报
回复
我是主要提取,森林火险的资料,很多天气预报都没有森林火险这块
燕飞7 2009-05-14
  • 打赏
  • 举报
回复
http://www.cnblogs.com/wlb/archive/2009/04/17/1438019.html

LZ可以参考下
xuStanly 2009-05-14
  • 打赏
  • 举报
回复
这是读sohu天气预报的
地址http://weather.news.sohu.com/city_inc.php?city=

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

using System.Net;
using System.Text;
using System.Text.RegularExpressions;

using AppCore.Sys;

namespace SST.App
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetWeather : BasePage
{
//private string city;
public override void ProcessRequest(HttpContext context)
{
//base.CheckRequest(context);
context.Response.ContentType = "text/plain";

string city = context.Server.UrlDecode(context.Request["city"]);
//city = context.Server.UrlDecode(context.Request["city"]);
if (string.IsNullOrEmpty(city)) city = "长沙";

WebClient wc = new WebClient();
string url = System.Configuration.ConfigurationManager.AppSettings["WeatherURL"];
//此处要对url的中文参数进行编码,根据目的页面的编码格式。
url += HttpUtility.UrlEncode(city, Encoding.GetEncoding("GB2312"));
//wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(GetSohuWeather);
//wc.DownloadStringAsync(new Uri(url));
string page = wc.DownloadString(url);
string weatherStr = GetSohuWeather(page);

Weather weather = new Weather();
weather.CityName = city;
weather.ReportStr = weatherStr;
context.Response.Write(Util.Tool.ToJSONString(weather));
}

private string GetSohuWeather(string page)
//private void GetSohuWeather(object sender, DownloadStringCompletedEventArgs e)
{
//if (!e.Cancelled && e.Error == null)
//{
string rst = "";

Regex r = new Regex(@"<td class=blu01>([\s\S]*?)</t", RegexOptions.Multiline | RegexOptions.IgnoreCase);
MatchCollection matches = r.Matches(page);
//MatchCollection matches = r.Matches(e.Result);
string today = matches[0].Groups[1].Value;
string tommorrow = matches[1].Groups[1].Value;

rst = @"<table width=100% border=0 cellpadding=3 cellspacing=0>";
rst += @"<tr><td align=left width=50% valign=top>今天 " + today + "</td>";
rst += @"<td align=left width=50% valign=top>明天 " + tommorrow + "</td></tr>";
rst += @"</table>";

//Weather w = new Weather();
//w.CityName = city;
//w.ReportStr = rst;
//HttpContext.Current.Response.Write(Util.Tool.ToJSONString(w));

return rst;
//}
}

class Weather
{
public string CityName;
public string ReportStr;
}
}
}

jdhlowforever 2009-05-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 HDNGO 的回复:]
http://topic.csdn.net/u/20081217/13/5a9075fc-feb1-4cde-96ac-5f982f7a1b7b.html

WebServices,直接搞定~
[/Quote]

怎么用呢?
HDNGO 2009-05-14
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20081217/13/5a9075fc-feb1-4cde-96ac-5f982f7a1b7b.html

WebServices,直接搞定~
HDNGO 2009-05-14
  • 打赏
  • 举报
回复
哪用这么麻烦。。。

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧