免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3961 | 回复: 12
打印 上一主题 下一主题

人穷,想弄个免费的天气预报,这个脚本怎么改良 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-08 20:16 |只看该作者 |倒序浏览
# curl http://wap.weather.com.cn/wap/weather/101280601.shtml |  sed -e 's#<[^>]*>##g' | grep -A2 -B2 "日" | awk 'NR>2 && NR <5'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2698    0  2698    0     0    766      0 --:--:--  0:00:03 --:--:--  1272
5月9日  
多云转阵雨 26℃/31℃微风

额,这怎么改良,感觉太多管道了。谢谢。

论坛徽章:
0
2 [报告]
发表于 2010-05-08 20:46 |只看该作者
把原始数据和需求帖出来吧。这样没法帮你啊

论坛徽章:
0
3 [报告]
发表于 2010-05-08 20:56 |只看该作者

这个页面噢,需求就是只要明天的天气预报。
http://wap.weather.com.cn/wap/weather/101280601.shtml

原始是这样的:
  1. # curl http://wap.weather.com.cn/wap/weather/101280601.shtml
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width; initial-scale=1.4; minimum-scale=1.0; maximum-scale=2.0"/>
  7. <title>深圳天气预报</title>
  8. <link href="/m/c/wap.css" rel="stylesheet" type="text/css" />
  9. </head>

  10. <body>
  11. <div class="weatherwapper">
  12. <div class="logo"><img src="/m/i/wap2/logo.jpg" /></div>
  13. <div class="weather">
  14. <h2><strong>深圳天气预报</strong></h2>
  15. <h3>2010-05-08 18时发布</h3>
  16. <div class="days">
  17. <dl style="background:#fff;">
  18. <dd>5月9日  <img src="/m/i/icon_weather/21x15/n01.gif" /><img src="/m/i/icon_weather/21x15/d03.gif" /></dd>
  19. <dt> 多云转阵雨 26℃/31℃<br />微风</dt>
  20. </dl>
  21. <dl >
  22. <dd>5月10日  <img src="/m/i/icon_weather/21x15/n10.gif" /><img src="/m/i/icon_weather/21x15/d10.gif" /></dd>
  23. <dt> 暴雨 23℃/28℃<br />微风</dt>
  24. </dl>
  25. <dl style="background:#fff;">
  26. <dd>5月11日  <img src="/m/i/icon_weather/21x15/n08.gif" /><img src="/m/i/icon_weather/21x15/d03.gif" /></dd>
  27. <dt> 中雨转阵雨 23℃/27℃<br />微风</dt>
  28. </dl>
  29. <dl >
  30. <dd>5月12日  <img src="/m/i/icon_weather/21x15/n03.gif" /><img src="/m/i/icon_weather/21x15/d01.gif" /></dd>
  31. <dt> 阵雨转多云 23℃/29℃<br />微风</dt>
  32. </dl>
  33. <dl style="background:#fff;">
  34. <dd>5月13日  <img src="/m/i/icon_weather/21x15/n01.gif" /><img src="/m/i/icon_weather/21x15/d01.gif" /></dd>
  35. <dt> 多云 24℃/30℃<br />微风</dt>
  36. </dl>
  37. </div>
  38. <div class="search">
  39. <form action="http://search.weather.com.cn/wap/search.php" method="post"><input type="text"  size="13" style="font-size:12px;"  name="city"/>
  40. <input class="button" type="submit" value="搜索" />
  41. </form>
  42. </div>
  43. </div>
  44. <!--24-->
  45. <div class="title">
  46. <dl>
  47. <dt><!--<a href="#">24小时</a> | <a href="#">48小时</a>--></dt>
  48. </dl>
  49. </div>


  50. <div class="end">
  51. <a href="/wap/">首页</a> | <a href="/wap/weather/101010100.shtml">天气</a> | <a href="/wap/news/">资讯</a> | <a href="/wap/alerts/">预警</a><br />
  52. 中国气象局公共气象服务中心 Copyright © 2000-2010<br />
  53. 未经授权 严禁非法复制或镜像   
  54. </div>


  55. <!-- START WRating v1.0 -->
  56. <script type="text/javascript" src="http://c.wrating.com/a1.js">
  57. </script>
  58. <script type="text/javascript">
  59. var vjAcc="860010-2099460100";
  60. var wrUrl="http://c.wrating.com/";
  61. vjTrack("");
  62. </script>
  63. <noscript><img src="http://c.wrating.com/a.gif?a=&c=860010-2099460100" width="1" height="1"/></noscript>
  64. <!-- END WRating v1.0 -->
  65. </div>
  66. </body>
复制代码

论坛徽章:
0
4 [报告]
发表于 2010-05-08 20:57 |只看该作者
我需要的是这个:

5月9日  
多云转阵雨 26℃/31℃微风

论坛徽章:
0
5 [报告]
发表于 2010-05-08 20:58 |只看该作者
额。。。人家提示:
# 中国气象局公共气象服务中心 Copyright © 2000-2010<br />
# 未经授权 严禁非法复制或镜像

- -!。。。

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
6 [报告]
发表于 2010-05-08 21:14 |只看该作者
是啊,帮楼主写脚本算不算犯法啊?万一被抓去躲猫猫、洗脸、做梦...,那可如何是好?

论坛徽章:
0
7 [报告]
发表于 2010-05-08 21:19 |只看该作者

  1. curl http://wap.weather.com.cn/wap/weather/101280601.shtml | awk -F '[<>]' '/^<dd>/{print $3;getline;print $3;exit}'

复制代码

论坛徽章:
0
8 [报告]
发表于 2010-05-08 21:20 |只看该作者
这个不犯法,那个网页是可以随便访问的

论坛徽章:
0
9 [报告]
发表于 2010-05-08 21:36 |只看该作者
sed  -n '/5.9/{N;N;:a;s/\n//;ta;p}' linux.137 | awk -F"[<>]" '{printf $3"\n"$11""$13}'
有点事~先写这个了~ 明天写个不用管道的

论坛徽章:
0
10 [报告]
发表于 2010-05-08 22:02 |只看该作者
sed  -n '/5.9/{N;N;:a;s/\n//;ta;p}' linux.137 | awk -F"[]" '{printf $3"\n"$11""$13}'
有点事~先写这个 ...
iori809 发表于 2010-05-08 21:36


他要的是明天的数据,应该不是特指5.9的数据
  1. 分析那个页面的源代码,发现,明天的数据就是第一个 <dd>和第一个<dl>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP