我正在尝试从下载的文本文件中提取数据(温度)wget
。
例如。wget http://www.weatherzone.com.au/sa/adelaide/adelaide
如何从文件中提取“18.6”的信息并将其复制到另一个文件以供另一个应用程序使用?
less adelaide
---snip---
'<span id="top_obs_temp" class="tempnow">18.6°C</span>'
---snip---
短暂性脑缺血发作
答案1
使用awk
$ wget http://www.weatherzone.com.au/sa/adelaide/adelaide
$ awk -F '[<|>|&]' '/tempnow/ {print $3}' adelaide
20.0
或一体式
$ wget -q -O- http://www.weatherzone.com.au/sa/adelaide/adelaide | awk -F '[<|>|&]' '/tempnow/ {print $3}'
20.1
只要标签中具有class
该值的属性,此方法即可起作用。tempnow
span
<span id="top_obs_temp" class="tempnow">18.6°C</span>
现在我被列入黑名单了哦哦 :P
wget http://www.weatherzone.com.au/sa/adelaide/adelaide
--2015-11-06 08:17:37-- http://www.weatherzone.com.au/sa/adelaide/adelaide
Resolving www.weatherzone.com.au (www.weatherzone.com.au)... 104.101.241.181
Connecting to www.weatherzone.com.au (www.weatherzone.com.au)|104.101.241.181|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2015-11-06 08:17:37 ERROR 403: Forbidden.