我有一个需要在 div 中显示水显示的新网站
我想显示:
- 地名
- c 或 f 中的天气
- 图标
- 图标含义的文字
我需要从加拿大(魁北克)获取天气,它必须看起来像:havre-saint-pierre:aujourdhui:18c,段落 nuageux
我在哪里以及如何获得最新的天气数据流?
雅虎有一个提要——它是 RSS,而不是 JSON——但它始终是最新的并且非常易于使用。您可以在此处找到更多详细信息:
忘记雅虎,最简单快捷的方法是使用谷歌天气 API,你没有指定你有什么编程技能,所以我假设你知道 php 和 html,这是你的代码:
<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?= print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?= $current[0]->temp_f['data'] ?>° F,
<?= $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<? foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?= $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?= $forecast->low['data'] ?>° F - <?= $forecast->high['data'] ?>° F,
<?= $forecast->condition['data'] ?>
</span>
</div>
<? endforeach ?>
</body>
</html>
祝你好运!
这也是一个很好的回应/答案:Parse weather data from Weatherbug in PHP