现在google提供的webservice接口还能用吗?如何通过编程调用google或百度的api?麻烦那位大侠能给出具体代码

解决方案 »

  1.   

    上午查一下,才知道google已经撤销 SOAP Search API 支持,http://www.google.org.cn/posts/google-give-up-soap-search-api-supports-after-3-years.html
    而通过AJAX Search API只能把结果显示到网页中,而无法在程序中获得。
    那还有其它办法在程序中利用google搜索获得结果?我的应用中是要把每条搜索结果整理到数据库中,以备使用。
    百度还提供基于webservice的search接口吗?
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Control Initialization</title>
        <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" type="text/javascript"></script>
        <script type="text/javascript">
        //<![CDATA[    function initialize() {
           ///////////////////**** 自定义控件 ****///////////////////////////
       
            var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
            crossLayer.getTileUrl =  function(tile, zoom) {
              return "./include/tile_crosshairs.png";
            }
            crossLayer.isPng = function() {return true;}        // 创建一个新的地图类型纳入瓦层
            var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0],
                                  crossLayer ];
            var mtTerCross = new GMapType(layerTerCross,
                                          G_PHYSICAL_MAP.getProjection(), "Ter+");        var map = new GMap2(document.getElementById("map_canvas"),
                { size: new GSize(640,320) } );
            map.addMapType(G_PHYSICAL_MAP);
            map.addMapType(mtTerCross);
            map.setCenter(new GLatLng(39.917,116.397), 8);
            map.addControl(new GLargeMapControl())        var mapControl = new GHierarchicalMapTypeControl();
            
            // 地图类型设置菜单中关系
            mapControl.clearRelationships();
            mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
            mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, "Crosshairs");
      
            // 添加控制后,您所指定的关系 
            map.addControl(mapControl);
    ///////////////////**** 自定义控件 ****///////////////////////////

    // 加载双击事件(提示GPoint与缩放级别)
          if (GBrowserIsCompatible()) {
      GEvent.addListener(map,"click", function(overlay,latlng) {     
              var myHtml = "GPoint 为: " + map.fromLatLngToDivPixel(latlng) + ",<br>缩放级别为:" + map.getZoom();
              map.openInfoWindow(latlng, myHtml);
            });
          }
        }
        //]]>
        </script>
      </head>  <body onload="initialize()" onunload="GUnload()">
        <div id="map_canvas" style="width: 640px; height: 320px"></div>
      </body>
    </html>
      

  3.   

    可以用cURL来抓取搜索结果页面的内容。
      

  4.   

    6楼的代码是google Map的吧,我想要的是在程序中怎样获得google搜索的结果
      

  5.   

    7楼说胡是一个办法,还要再解析html页面,好像比较麻烦吧,还有更简单的办法吗?
      

  6.   

    7楼说的是一个办法,但是还要再解析html页面,好像比较麻烦吧,还有更简单的办法吗?
      

  7.   

    读一下code.Google.com/search的API说明
    你说的代码我在zendfreamwork框架的Demo中看到过的 不难 就是用Ajax完成于Yahoo和Google的数据交互
    甚至不需要写PHP代码 数据可以与远程的xml wsdl缓存交互 也可以直接调用Yahoo的收索API 据我所知Google和baidu目前不开放API Google是部分开放 百度不开放 Yahoo100%开放
      

  8.   

    楼主居然没听过XMLHTTP吗?就是AJAX使用的。在后台程序里一样可以创建和使用。
    用它传递参数并接收到GOOGLE返回的结果,把它当作一个大字串,进行搜索定位提取。就那些字串操作函数,不用多说吧。
      

  9.   

    我用过微软地图,也许对你有帮助:
    地图标记定位在某一点
    VitualEarth.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
       <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">      <script type="text/javascript" src="http://dev.ditu.live.com/mapcontrol/mapcontrol.ashx?v=6.1"></script>      <script type="text/javascript">
             var map = null;         var LA = new VELatLong(43.815887948922544, 87.5988006591797);         var pinPoint = null;
             var pinPixel = null;
                      
             function GetMap()
             {
                map = new VEMap('myMap');
                map.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);            AddPin();
             }         function AddPin()
             {
                // Add a new pushpin to the center of the map.
                pinPoint = map.GetCenter();
                pinPixel = map.LatLongToPixel(pinPoint);
                map.AddPushpin(pinPoint);
             }
          </script>
       </head>
       <body onload="GetMap();">
          <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
       </body>
    </html>
    鼠标点击定位坐标点:
    VitualEarth_GetPoint.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
       <head>
          <title></title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <style type="text/css">
          body
          {
            font-size:12px;
          }
          </style>
          <script type="text/javascript" src="http://dev.ditu.live.com/mapcontrol/mapcontrol.ashx?v=6.1"></script>
          <script type="text/javascript">
             var map = null;
             var pixel = null;
             var clickEvent = null;
             
             function GetMap()
             {
                map = new VEMap('myMap');
                map.LoadMap();
                map.AttachEvent("onclick", PixelClick);
             }
             
             function PixelClick(e)
             {
                var x = e.mapX;
                var y = e.mapY;
                pixel = new VEPixel(x, y);
                var LL = map.PixelToLatLong(pixel);
                info.innerHTML = "Pixel X: " + x + " | Pixel Y: " + y + "<br /> LatLong: " + LL;
                returnVal.innerText = LL;
             }
          </script>
       </head>
       <body onload="GetMap();" style="font-family:Arial">
          <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
          <div id="mapInfo">
            在地图上单击选择地理位置,点<a href="#" onclick="opener.document.getElementById('ctl00$ContentPlaceHolder1$txt_mapinfo').value=document.getElementById('returnVal').innerText;window.close();">这里</a>返回父窗体.<br />
          <span id="info"></span><div id="returnVal"></div>
          </div>
       </body>
    </html>
      

  10.   

    你看一下google提供的AJAX search API,它隐藏了XMLHTTP,只给提供了一个调用函数,只能把结果显示在网页上而无法在程序中获得结果。
      

  11.   

    HTML页面的解析也没有想象的麻烦,搜索结果的HTML代码具有很大的相似形,cURL抓取后用正则表达式匹配就可以了。
    如果baidu或者google的API不提供纯搜索结果返回,也只能用这个笨办法。
      

  12.   

    我用过google 分析器的api~~当时是要把站点对应的google数据生成flash图形并且能按各种方式查询!
    但是我用的是一个网上开源的类和openflashchart!