Frage

How do I adjust this Google News script - using variables, I would assume - to place the current year and current month in the boolean search - specifically, the line that starts with "tabbed.execute(... ?"

My end goal is to have this script return the search terms in context of the current year and month. Thanks for helping a newbie!

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

function OnLoad() {

  // create a tabbed mode search control
  var tabbed = new google.search.SearchControl();


  // create our searchers.  There will now be 4 tabs.
  tabbed.addSearcher(new google.search.VideoSearch());
  tabbed.addSearcher(new google.search.NewsSearch());
  tabbed.addSearcher(new google.search.BlogSearch());
  tabbed.addSearcher(new google.search.ImageSearch());


  // draw in tabbed layout mode
  var drawOptions = new google.search.DrawOptions();
  drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);

  // Draw the tabbed view in the content div
  tabbed.draw(document.getElementById("stephennews"), drawOptions);


  // Search!
  tabbed.execute("'SEARCHTERM1' AND 'SEARCHTERM2' AND '2013' AND 'MARCH'");
}
google.setOnLoadCallback(OnLoad);
War es hilfreich?

Lösung

I think found my answer. I won't need to insert another variable with a current date forumula. I could probably let Google do all the work for me with boolean:

The past x number of months is notated as "m[INSERT NUMBER]" Likewise, The past x number of days is notated as "d[INSERT NUMBER]"

So the search line in my script would read:

tabbed.execute("'SEARCHTERM1' AND 'SEARCHTERM2' AND 'y[1]' AND 'm[1]'");

Google's XML API reference

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top