userSpace.fillScraper = function(){
witscript.views.scrapers.editor.datasheet.setCellValue(0, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(0, 2, "Page Title");
witscript.views.scrapers.editor.datasheet.setCellValue(0, 3, '<title');
witscript.views.scrapers.editor.datasheet.setCellValue(0, 4, "</title>");
witscript.views.scrapers.editor.datasheet.setCellValue(1, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(1, 2, "CumulatedMagnitude");
witscript.views.scrapers.editor.datasheet.setCellValue(1, 3, 'callout">');
witscript.views.scrapers.editor.datasheet.setCellValue(1, 4, "</span>");
witscript.views.scrapers.editor.datasheet.setCellValue(1, 6, "#SUM#");
witscript.views.scrapers.editor.datasheet.setCellValue(2, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(2, 2, "Average");
witscript.views.scrapers.editor.datasheet.setCellValue(2, 3, 'callout">');
witscript.views.scrapers.editor.datasheet.setCellValue(2, 4, "</span>");
witscript.views.scrapers.editor.datasheet.setCellValue(2, 6, "#AVERAGE#");
witscript.views.scrapers.editor.datasheet.setCellValue(3, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(3, 2, "Maximum");
witscript.views.scrapers.editor.datasheet.setCellValue(3, 3, 'callout">');
witscript.views.scrapers.editor.datasheet.setCellValue(3, 4, "</span>");
witscript.views.scrapers.editor.datasheet.setCellValue(3, 6, "#MAX#");
witscript.views.scrapers.editor.datasheet.setCellValue(4, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(4, 2, "Number");
witscript.views.scrapers.editor.datasheet.setCellValue(4, 3, 'callout">');
witscript.views.scrapers.editor.datasheet.setCellValue(4, 4, "</span>");
witscript.views.scrapers.editor.datasheet.setCellValue(4, 6, "#COUNT#");
witscript.views.scrapers.editor.datasheet.setCellValue(5, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(5, 2, "Locations");
witscript.views.scrapers.editor.datasheet.setCellValue(5, 3, 'header">');
witscript.views.scrapers.editor.datasheet.setCellValue(5, 4, "</");
witscript.views.scrapers.editor.datasheet.setCellValue(5, 6, "#CONCAT#");
witscript.views.scrapers.editor.datasheet.setCellValue(6, 1, true);
witscript.views.scrapers.editor.datasheet.setCellValue(6, 2, "Latest Event");
witscript.views.scrapers.editor.datasheet.setCellValue(6, 3, 'subheader">');
witscript.views.scrapers.editor.datasheet.setCellValue(6, 4, "</");
witscript.views.scrapers.editor.datasheet.setCellValue(6, 6, "#MAX#");
witscript.menutree.focus();
}
wizardKit.say(this.parentNode);
witscript.views.scrapers.display();
if(witscript.views.scrapers.editor.isVisible){
if(witscript.views.scrapers.editor.isVisible()){
witscript.views.scrapers.editor.manageButton.click();
if(userSpace.waitOK) witscript.wait(7000,function() {return witscript.views.scrapers.manager.isVisible();});
}
} else {
witscript.views.scrapers.editor.saveButton.click();
if(userSpace.waitOK) witscript.wait(1000);
witscript.views.scrapers.editor.manageButton.click();
}
wizardKit.hideCatch();
wizardKit.hideLog();
if(!(/earthquake.usgs.gov\/earthquakes\/map/.test(witscript.toolbar.urlBar.getValue()))){
witscript.views.page.load("http://earthquake.usgs.gov/earthquakes/map/");
if(userSpace.waitOK) witscript.wait(10000);
}
//alert(1)
witscript.views.scrapers.editor.sourceSelector.DOM.click()
//alert(2)
var currentAutomator = witscript.views.scrapers.manager.currentAutomator();
if (currentAutomator && currentAutomator.automatorId == -1) {
// XXX seems outdated. Check and remove
witscript.views.scrapers.editor.manageButton.click();
}
if (!currentAutomator || !userSpace.automatorName || userSpace.automatorName != currentAutomator.name || !(/Tutorial Earthquake/.test(currentAutomator.name))) {
witscript.views.scrapers.manager.createAutomator("Tutorial Earthquake Scraper");
userSpace.automatorName = views.scrapers.manager.currentAutomator().name;
witscript.views.scrapers.editor.url.setValue("http://earthquake.usgs.gov/earthquakes/map/");
}
witscript.views.scrapers.manager.editButton.click();
if(userSpace.waitOK) witscript.wait(1000);
if(userSpace.waitOK) witscript.wait(1000,function(){return views.scrapers.source.isLoaded();});
if(userSpace.waitOK) witscript.wait(300);
witscript.views.scrapers.editor.display();
if(userSpace.waitOK) witscript.wait(100);
witscript.views.scrapers.editor.datasheet.focus();
if(userSpace.waitOK) witscript.wait(100);
witscript.views.scrapers.source.scrollToPercent(.4);
if(userSpace.waitOK) witscript.wait(100);
witscript.views.scrapers.source.findBar.toggleHighlight(false);
witscript.views.scrapers.source.findBar.toggleHighlight(true, '/class="mag"/gi');
if(userSpace.waitOK) witscript.wait(100);
userSpace.fillScraper();
if(userSpace.waitOK) witscript.wait(1500);
Here is our scraper
The page contains a table of the latest events with their time, magnitude and location. Instead of grabbing all these elements, we want to display the sum, average and maximum of the magnitudes, the number of earthquakes, a list of the locations and the time of the latest.
All this is done by placing the corresponding function in the replace field.
userSpace.fillScraper();
witscript.views.scrapers.editor.sourceSelector.DOM.click();
This is an AJAX site and the data is dynamically added to the page. The source should therefore be set to dynamic (pale yellow background).
wizardKit.say(this.parentNode);
Applying the scraper
userSpace.fillScraper();
witscript.views.scrapers.editor.executeButton.click();
witscript.menutree.focus();
Instead of creating a new column for each occurrence, the #SUM#, #COUNT#, #MAX#, #MIN#, #AVERAGE# and #CONCAT# functions placed in the replace field, consolidate all the matches in a single computed cell.
wizardKit.say(this.parentNode);