谷歌新闻Api自定义搜索

问题描述:

我在我的HTML文件中有这个Java脚本....我有一个关键字搜索我的网页,我想通过关键字搜索到API。这是我目前拥有的:不确定我出错的地方,它没有产生任何搜索结果。谷歌新闻Api自定义搜索

,我在代码中有

CNN 

,这是我的搜索变量应该传递...

<script type="text/javascript"> 

    google.load('search', '1'); 

    function OnLoad() 
    { 
     var customSearchControl = new google.search.CustomSearchControl('CNN'); 
     customSearchControl.setResultSetSize(google.search.Search.FILTERED_ 
                  CSE_RESULTSET); 
     customSearchControl.draw('cse'); 
     customSearchControl.execute("$q"); 
    } 
    google.setOnLoadCallback(OnLoad); 

    // tell the searcher to draw itself and tell it where to attach 
     // create a drawOptions object 
     var drawOptions = new google.search.DrawOptions(); 

     // tell the searcher to draw itself in tabbed mode 
     drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 
     searchControl.draw(document.getElementById("content"),drawOptions); 

     searchControl.addSearcher(new google.search.NewsSearch()); 
    } 

    google.setOnLoadCallback(OnLoad); 

    </script> 

我有同样的问题,我觉得现在的问题是,这些自2010年以来,专业CSE已被“弃用”(参见http://code.google.com/apis/websearch/),现在它们只是不起作用。新的工作是用于一般的网络搜索和图像搜索。如果这是您的目标,您可以限制网络搜索到CNN网站。见What are the alternatives now that the Google web search API has been deprecated?