天气预报api接口 直接 抓取 http://www.google.com/ig/api?weather=qinhuangdao 的内容,是xml。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SimpleXMLhttp://php.net/manual/en/book.simplexml.php 恩,通过城市获取google weather,得到XML数据然后用PHP解析就OK了 推荐google天气预报,发送http://www.google.com/ig/api?weather=城市名,返回xml,用php解析后再根据的你自己的网页使用这个结果就好,php解析xml可以参考http://blog.sina.com.cn/s/blog_7d0aefbe0100z18y.html $.ajax({ type: 'GET', url: global.services.php', dataType: 'json', success: function( Weather ) { $('div[class=weather]>p:first' ).html( '<font color=#333><b>' + Weather.weatherinfo.city + '气温:' + '</b></font> ' + Weather.weatherinfo.temp1) $('div[class=weather]>p:last' ).html( ' <img height=\'18px\' width=\'25px\' src=\'http://m.weather.com.cn/img/b' + Weather.weatherinfo.img1 + '.gif\' /> ' + Weather.weatherinfo.weather1 + ' ' + Weather.weatherinfo.wind1) } })------------------------------------------------------------------global.services.php代码如下echo file_get_contents('http://m.weather.com.cn/data/101270101.html'); php页面这样写就可以了:<?php header("content-type:text/html;charset=utf-8");$weather = file_get_contents("http://www.weather.com.cn/data/sk/101091101.html"); echo $weather; ?> 这个是获取到了秦皇岛的信息,不过是JSON字符串,简单处理一下就好了哦!很简单的! http://weather.xixik.com/这里有,根据IP显示的,样式很多很齐全 ++1json_decode($weather,true);然后取你要的数据 http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data/cityinfo/101010100.html http://m.weather.com.cn/data/101010100.html上述代码替换河北秦皇岛,101091101河北秦皇岛青龙,101091102河北秦皇岛昌黎,101091103河北秦皇岛抚宁,101091104河北秦皇岛卢龙,101091105河北秦皇岛北戴河,101091106 我以前写过你写的这个抓取,为什么我抓取出来的是页面呢?不是代码输出的就是json格式的数据啊.... 我以前写过你写的这个抓取,为什么我抓取出来的是页面呢?不是代码输出的就是json格式的数据啊....版主 你看看这段代码header("content-type:text/html;charset=utf-8");$a = file_get_contents("http://www.233.com/teacher/zhinan/shanxi1/20130413/142918550.html");echo $a;没有问题吧?也是file_get_contents。为什么他输出的就是页面呢? $curl = curl_init();curl_setopt($curl, CURLOPT_URL, 'http://www.weather.com.cn/data/sk/101091101.html');curl_setopt($curl, CURLOPT_HEADER, 1);。curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36');curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);$data = curl_exec($curl);curl_close($curl);print_r($data); 新手PHP问题 做项目,想起陈年旧事-关于php项目的报价 PHP 读写文件编码问题 关于UCHOME一些代码修改的问题,请高手帮我看一下,我修改的代码有什么问题不? php//gd库问题 关于phpadmin的问题 小菜问题 偶的这个判断语句咋没起作用也 谁有PHP直接使用QQWry.dat的程序? JAVASCRIPT函数中的变量能传给PHP吗? html 文件上传一定要放在表单里吗 关于CURL
success: function( Weather ) {
$('div[class=weather]>p:first' ).html( '<font color=#333><b>' + Weather.weatherinfo.city + '气温:' + '</b></font> ' + Weather.weatherinfo.temp1)
$('div[class=weather]>p:last' ).html( ' <img height=\'18px\' width=\'25px\' src=\'http://m.weather.com.cn/img/b' + Weather.weatherinfo.img1 + '.gif\' /> ' + Weather.weatherinfo.weather1 + ' ' + Weather.weatherinfo.wind1)
}
})------------------------------------------------------------------
global.services.php代码如下echo file_get_contents('http://m.weather.com.cn/data/101270101.html');
<?php
header("content-type:text/html;charset=utf-8");
$weather = file_get_contents("http://www.weather.com.cn/data/sk/101091101.html");
echo $weather;
?> 这个是获取到了秦皇岛的信息,不过是JSON字符串,简单处理一下就好了哦!很简单的!
这里有,根据IP显示的,样式很多很齐全
++1
json_decode($weather,true);然后取你要的数据
http://www.weather.com.cn/data/cityinfo/101010100.html
http://m.weather.com.cn/data/101010100.html上述代码替换河北秦皇岛,101091101
河北秦皇岛青龙,101091102
河北秦皇岛昌黎,101091103
河北秦皇岛抚宁,101091104
河北秦皇岛卢龙,101091105
河北秦皇岛北戴河,101091106
版主 你看看这段代码header("content-type:text/html;charset=utf-8");
$a = file_get_contents("http://www.233.com/teacher/zhinan/shanxi1/20130413/142918550.html");
echo $a;没有问题吧?也是file_get_contents。为什么他输出的就是页面呢?
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.weather.com.cn/data/sk/101091101.html');
curl_setopt($curl, CURLOPT_HEADER, 1);。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($curl);
curl_close($curl);
print_r($data);