直接 抓取 http://www.google.com/ig/api?weather=qinhuangdao 的内容,是xml。

解决方案 »

  1.   

    SimpleXMLhttp://php.net/manual/en/book.simplexml.php
      

  2.   

    恩,通过城市获取google weather,得到XML数据然后用PHP解析就OK了
      

  3.   

    推荐google天气预报,发送http://www.google.com/ig/api?weather=城市名,返回xml,用php解析后再根据的你自己的网页使用这个结果就好,php解析xml可以参考http://blog.sina.com.cn/s/blog_7d0aefbe0100z18y.html
      

  4.   

    $.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'); 
      

  5.   

    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字符串,简单处理一下就好了哦!很简单的!
      

  6.   

    http://weather.xixik.com/
    这里有,根据IP显示的,样式很多很齐全
      

  7.   


    ++1
    json_decode($weather,true);然后取你要的数据
      

  8.   

    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
      

  9.   

    我以前写过你写的这个抓取,为什么我抓取出来的是页面呢?不是代码输出的就是json格式的数据啊....
      

  10.   

    我以前写过你写的这个抓取,为什么我抓取出来的是页面呢?不是代码输出的就是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。为什么他输出的就是页面呢?
      

  11.   


    $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);