c# winform 如何获得http://qq.ip138.com/weather/xinjiang/WuLuMuQi.htm这个网址中的天气预报

Sant11 2008-06-13 01:14:08
如题:
c# winform 如何获得http://qq.ip138.com/weather/xinjiang/WuLuMuQi.htm这个网址中的天气预报
...全文
865 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
parfum 2008-06-13
  • 打赏
  • 举报
回复
这里好详细,基本上可以直接Copy代码:http://www.dotnetthink.com/?p=13
Sant11 2008-06-13
  • 打赏
  • 举报
回复
WebBrowser web = new WebBrowser();
web.DocumentText = "";//取得的html text。
HtmlElementCollection coll=web.Document.GetElementsByTagName("table");
foreach (HtmlDocument d in coll)
{

}
那么用这个方法如何获取呢?
ericzhangbo1982111 2008-06-13
  • 打赏
  • 举报
回复
这个webservice是收费的.
Sant11 2008-06-13
  • 打赏
  • 举报
回复
ericzhangbo1982111
十分感谢您。
WebBrowser web = new WebBrowser();
web.DocumentText = "";//取得的html text。
HtmlElementCollection coll=web.Document.GetElementsByTagName("table");
foreach (HtmlDocument d in coll)
{

}
这里如何取内容呢?我是初学者。谢谢你帮助。
Sant11 2008-06-13
  • 打赏
  • 举报
回复

WindowsApplication2.com.wopos.www.Weather aa =
new WindowsApplication2.com.wopos.www.Weather();
this.textBox2.Text = aa.getWeather("乌鲁木齐");
aa.Dispose();

我这样引用http://www.wopos.com/webservice/Weather.asmx 了这个
可提示
无权限访问,若要开通请Q 76445866 .System.NullReferenceException: 未将对象引用设置到对象的实例。
在 Weather.getWeather(String mCity)
是我程序又问题还是这个不是免费的?
ericzhangbo1982111 2008-06-13
  • 打赏
  • 举报
回复
取得文件应该里面有这些东西
可以用
WebBrowser web = new WebBrowser();
web.DocumentText = "";//取得的html text。
HtmlElementCollection coll=web.Document.GetElementsByTagName("table");
foreach (HtmlDocument d in coll)
{

}



<table width="700" borderColorDark="#ffffff" borderColorLight="#008000" border="1" cellspacing="0" cellpadding="1">
<tr bgColor="#6699cc">
<th width="12%" class="tdc1">日期</td>
<th class="tdc1">2008年6月13日</td>
<th class="tdc1">2008年06月14日</td>
<th class="tdc1">2008年06月15日</td>
<th class="tdc1">2008年06月16日</td>
<th class="tdc1">2008年06月17日</td>
</tr>
<tr>
<td align="center">天气</td>
<td><img src="/image/b2.gif" alt="阴" /><img src="/image/b0.gif" alt="晴" /><br/>阴 - 晴</td>
<td><img src="/image/b0.gif" alt="晴" /><br/>晴</td>
<td><img src="/image/b0.gif" alt="晴" /><img src="/image/b1.gif" alt="多云" /><br/>晴 - 多云</td>
<td><img src="/image/b2.gif" alt="阴" /><img src="/image/b3.gif" alt="阵雨" /><br/>阴 - 阵雨</td>
<td><img src="/image/b1.gif" alt="多云" /><img src="/image/b7.gif" alt="小雨" /><br/>多云 - 小雨</td>
</tr>
<tr>
<td align="center">气温</td>
<td>28℃~17℃</td>
<td>30℃~18℃</td>
<td>32℃~19℃</td>
<td>30℃~18℃</td>
<td>28℃~18℃</td>
</tr>
<tr>
<td align="center">风向</td>
<td>微风</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
liujb526 2008-06-13
  • 打赏
  • 举报
回复
学习
Sant11 2008-06-13
  • 打赏
  • 举报
回复
ericzhangbo1982111
我能取出它的源文件。
可是不知道怎么从源文件里读取。
不知道用什么办法。
Sant11 2008-06-13
  • 打赏
  • 举报
回复
我的怎么没有System.Web.HttpUtility这个
Sant11 2008-06-13
  • 打赏
  • 举报
回复
那么怎么引用webservce?
烈火焚身 2008-06-13
  • 打赏
  • 举报
回复
up
豆丁_ 2008-06-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jacklau88 的回复:]
天气预报都有webservce,你只要在程序中引用一下就可以了。
[/Quote]
yagebu1983 2008-06-13
  • 打赏
  • 举报
回复
学习了!!
帮你顶!!
天气预报有个webservice,你直接调用即可!!
sxmonsy 2008-06-13
  • 打赏
  • 举报
回复
用WebSerice访问天气预报:

[WebMethod]

public string GetWeather(string city)
{
string weacherhtml = string.Empty;
//转换输入参数的编码类型
string mycity = System.Web.HttpUtility.UrlEncode(city, System.Text.UnicodeEncoding.GetEncoding("GB2312"));
//初始化新的 WebRequest
HttpWebRequest webrt = (HttpWebRequest)WebRequest.Create("http://php.weather.sina.com.cn/search.php?city=" + mycity);
HttpWebResponse webrs = (HttpWebResponse)webrt.GetResponse();
//从Internet资源返回数据流
Stream stream = webrs.GetResponseStream();
//读取数据流
StreamReader srm = new StreamReader(stream, System.Text.Encoding.Default);
//读取数据
weacherhtml = srm.ReadToEnd();
srm.Close();
stream.Close();
webrs.Close();
//针对不同的网站,请查看HTML源文件
int start = weacherhtml.IndexOf("天气状况 begin"); //取的字符位置
int end = weacherhtml.IndexOf("天气状况 end");
return weacherhtml.Substring(start + 14, end - start);
}


csShooter 2008-06-13
  • 打赏
  • 举报
回复

使用WebService 访问多好!

http://www.wopos.com/webservice/Weather.asmx


jacklau88 2008-06-13
  • 打赏
  • 举报
回复
天气预报都有webservce,你只要在程序中引用一下就可以了。
ericzhangbo1982111 2008-06-13
  • 打赏
  • 举报
回复


public static string GetQQWether(string ps_CityName)
{
string strCity = StrConv(ps_CityName,"GB2312");

string myuri="http://qq.ip138.com/weather/xinjiang/WuLuMuQi.htm;
WebRequest webr=WebRequest.Create(myuri);

Stream rc=webr.GetResponse().GetResponseStream();

StreamReader read=new StreamReader(rc,System.Text.Encoding.Default);
string abc=read.ReadToEnd();
return
ericzhangbo1982111 2008-06-13
  • 打赏
  • 举报
回复
/// <summary>
/// 根据城市取得天气预报信息
/// </summary>
/// <param name="ps_CityName">城市中文名称 如:福州</param>
/// <returns></returns>
public static string GetSinaWether(string ps_CityName)
{
string strCity = StrConv(ps_CityName,"GB2312");

//string myuri="http://appnews.qq.com/cgi-bin/news_qq_search?city="+city;
string myuri="http://weather.news.sina.com.cn/cgi-bin/figureWeather/simpleSearch.cgi?city="+strCity;
WebRequest webr=WebRequest.Create(myuri);


Stream rc=webr.GetResponse().GetResponseStream();

StreamReader read=new StreamReader(rc,System.Text.Encoding.Default);
string abc=read.ReadToEnd();
int l1=abc.IndexOf("今日天气");
string restr="<font face=黑体 style=font-size:18px;>"+abc.Substring(l1).Replace("<br>","").Replace("<td style=","").Replace("class=l15>","").Replace("color:#083887","").Replace("</td>","").Replace("</tr>","").Replace("</table>","").Replace("</body>","").Replace("</html>","");
return restr.Replace("50","20");
}

/// <summary>
/// 根据城市取得天气预报信息
/// </summary>
/// <param name="ps_CityName">城市中文名称 如:福州</param>
/// <returns></returns>
public static string GetQQWether(string ps_CityName)
{
string strCity = StrConv(ps_CityName,"GB2312");

string myuri="http://appnews.qq.com/cgi-bin/news_qq_search?city="+strCity;
WebRequest webr=WebRequest.Create(myuri);

Stream rc=webr.GetResponse().GetResponseStream();

StreamReader read=new StreamReader(rc,System.Text.Encoding.Default);
string abc=read.ReadToEnd();
return abc;
}

/// <summary>
/// 编码转换
/// </summary>
/// <param name="strIn"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public static string StrConv(string strIn, string encoding)
{
return System.Web.HttpUtility.UrlEncode(strIn,System.Text.Encoding.GetEncoding(encoding));
}
Deathsign 2008-06-13
  • 打赏
  • 举报
回复
把网页得到TOXML。。。用XML取出来··

110,568

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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