Manipulating Google custom search results

Discussion in 'HTML & Website Design' started by Goddy, Jul 1, 2010.

  1. #1
    Hi,

    The following google custom search code searches only youtube.com and gives the results.

    What I want to do is to replace "watch?" in all youtube links to "watch_popup?"
    Ex. http://www.youtube.com/watch?v=pRpeEdMmmQ0 should be replaced to http://www.youtube.com/watch_popup?v=pRpeEdMmmQ0

    After that I want google to open the first link automatically(just like "I'm feeling lucky" function)

    I don't know much about coding so please help me.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>Custom Search Engine</title>
    
      <script src="http://www.google.com/jsapi" type="text/javascript"></script>
      <script type="text/javascript">
        // Load the Search API
        google.load('search', '1');
    
        // Set a callback to load the Custom Search Element when you page loads
        google.setOnLoadCallback(
          function(){
         var customSearchControl = new google.search.CustomSearchControl('002165374204510623583:aqvokn54kem');
    
            // Use "mysite_" as a unique ID to override the default rendering.
            google.search.Csedr.addOverride("mysite_");
    
            // Draw the Custom Search Control in the div named "CSE"
            customSearchControl.draw('cse');
    
            // Execute an initial search
            customSearchControl.execute("waka+waka");
          },
        true);
      </script>
    </head>
    <body>
    
      <div style="display:none">
    
        <!-- Return the unescaped result URL.-->
        <div id="mysite_webResult">
          <div class="gs-webResult gs-result"
    data-vars="{longUrl:function() {
              var i = unescapedUrl.indexOf(visibleUrl);
              return i < 1 ? visibleUrl : unescapedUrl.substring(i);}}">
           
     <!-- Build the result data structure.-->
            <table>
              <tr>
                <td valign="top">
                  <div data-if="Vars.richSnippet" data-attr="0"
                    data-body="render('thumbnail',richSnippet,{url:unescapedUrl,target:target})"></div>
                </td>
                <td valign="top">
    
                  <!-- Append results within the table cell.-->
                  <div class="gs-title">
                    <a class="gs-title" data-attr="{href:unescapedUrl,target:target}"
                      data-body="html(title)"></a>
                  </div>
    
    </div>
    
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    
      <!-- Div container for the searcher.-->
      <div id="cse"></div>
    
    </body>
    </html>
    
    Code (markup):

     
    Last edited: Jul 1, 2010
    Goddy, Jul 1, 2010 IP