我遇到谷歌天气api的问题我现在已经使用这个脚本http://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/了一段时间但是早些时候我收到了这个错误:
警告:simplexml_load_file() [function.simplexml负荷文件]: //www.google.com/ig/api?weather=bermuda:2: 解析器错误:打开和结束标记 不匹配:元线1和HEAD /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml负荷文件]: 302已移动 在 /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml-load-file]:^ in /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml负荷文件]: //www.google.com/ig/api?weather=bermuda:6: 解析器错误:打开和结束标记 不匹配:HEAD第1行和HTML /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml负荷文件]: 在 /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml-load-file]:^ in /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml负荷文件]: //www.google.com/ig/api?weather=bermuda:7: 解析器错误:数据过早结束 在标记HTML行1中 /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml-load-file]:in /home/webmx04/public_html/weather/widgetlive1.php 在第3行
警告:simplexml_load_file() [function.simplexml-load-file]:^ in /home/webmx04/public_html/weather/widgetlive1.php 在第3行
致命错误:调用成员函数 xpath()在非对象中 /home/webmx04/public_html/weather/widgetlive1.php 第4行
任何人都可以帮助我,谢谢你
我的代码:
<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=bermuda');
$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>
<div id="widget-wrapper"><!-- start widget-wrapper-->
<div class="weather"><!-- start weather-->
<h2><a href="/section/weather" title="More on Weather" target="_top">Current Weather</a></h2>
<a href="/section/weather" target="_top"><img src="<?= 'http://www.rgbdahosting.com' . $current[0]->icon['data']?>" alt="More on Weather"?></a>
<span class="condition">
<a href="/section/weather" title="More on Weather" target="_top"><H4><?= $current[0]->temp_f['data'] ?>°F</H4>
<p><?= $current[0]->condition['data'] ?></p></a>
</span>
</div><!-- end weather-->
</div> <!-- end widget-wrapper-->
</body>
答案 0 :(得分:1)
显然Google将Captcha引入了他们的Weather API。它将工作一次,两次或三次,但在来自同一服务器的几次请求后,它将要求重现Captcha。你的插件无法做到的事情。
我不知道如何解决这个问题,所以看起来我们必须找到另一个使用的天气API。如果我错了请纠正我,这会有所帮助。
Google天气的缓存结果也可能有所帮助。 15或30分钟内的1个请求应该可以接受,不是吗?