WIZ-MACRO01.ALT

This is an OutWit Tutorial file.


Testing Browser...
OutWit Hub Pro - Macros
Application walkthrough: creating a macro
userSpace.restoreOriginalPrefs = function restoreOriginalPrefs(){ if(userSpace.originalPrefs){ for(var thePref in userSpace.originalPrefs){ witscript.setPreference(thePref, userSpace.originalPrefs[thePref]); } } } userSpace.storeOriginalPrefs = function storeOriginalPrefs(){ if(!userSpace.originalPrefs){ userSpace.originalPrefs = {}; userSpace.originalPrefs["browse.tempo.min"] = witscript.getPreference("browse.tempo.min"); userSpace.originalPrefs["browse.tempo.max"] = witscript.getPreference("browse.tempo.max"); userSpace.originalPrefs["images.ondemandonly"] = witscript.getPreference("images.ondemandonly"); userSpace.originalPrefs["page.ignorePlugins"] = witscript.getPreference("page.ignorePlugins"); userSpace.originalPrefs["page.ignoreImages"] = witscript.getPreference("page.ignoreImages"); userSpace.originalPrefs["tableMinRows"] = witscript.getPreference("tableMinRows"); } } userSpace.setWizardPrefs = function setWizardPrefs(){ witscript.setPreference("browse.tempo.min", "2000"); witscript.setPreference("browse.tempo.max", "3500"); witscript.setPreference("images.ondemandonly", false); // witscript.setPreference("page.ignorePlugins", false); witscript.setPreference("page.ignoreImages", false); witscript.setPreference("tableMinRows", "1"); }

How Macros Work

This tutorial will show you how to create a macro. A macro is an automator which allows you to execute a complex extraction process in a single click:

It configures the Hub the way you want, explores pages, extracts data, exports it then restores the original configuration.

While this window is showing instructions, the user interface of OutWit Hub remains operational.

You can still interact normally with the application and you can move this tutorial window around on the screen to better see the parts of the interface that you want.

userSpace.waitOK = witscript.version("4") || !/Firefox\/2\d\./.test(navigator.userAgent); // XXX ??? userSpace.eyeCatcherOK = witscript.version("3.0") || !(wizardKit.platform=="mac" && /firefox/i.test(navigator.userAgent) && /rv:1[2-7]/i.test(navigator.userAgent)); userSpace.eyeCatcherOK = !(wizardKit.platform=="mac" && /firefox/i.test(navigator.userAgent) && /rv:1[2-7]/i.test(navigator.userAgent)); if(/Firefox\/2\d\./.test(navigator.userAgent)) { userSpace.eyeCatcherOK = false; wizardKit.typeCellValue = function typeCellValue(tree, row, column, value){ tree.setCellValue(row, column, value); tree.startEditing(row, column); //witscript.wait(200); tree.stopEditing(true); //witscript.wait(200); }; } if (/Firefox\/[23]\./.test(navigator.userAgent)){ alert("OutWit wizards cannot run on your version of Firefox. Please update to the current version and try again."); wizard.close(); } else if (!("witscript" in window)){ // XXX FIXME: have to put the following wait, or we get both this alert and the one by data-kernelVersion // witscript.wait(100); alert("This wizard is not compatible with your version of the OutWit Kernel. Please download the latest version (2.0.1 or higher)"); wizard.close(); } else if (!witscript.version || !witscript.version("2.0.1")){ alert("This wizard is not compatible with your version of the OutWit Kernel. Please download the latest version (2.0.1 or higher)"); wizard.close(); } if(witscript.version()=="2.1.1.4"){ alert("Version 2.1.1.5 was released with important fixes. Please update and restart the tutorial."); } if(witscript.version("2.1")){$(".owui-wizard-homelink").html("Hub Tutorials")}; wizardKit.hideCatch(); wizardKit.hideLog(); userSpace.storeOriginalPrefs(); userSpace.setWizardPrefs(); witscript.logPanel.setAttribute("height",0);
wizardKit.say(this.parentNode); witscript.views.page.display();
// For some reason a script in owui-wizard-page is not executed if there are steps: // alert("This is page 2.0");
wizardKit.say(this.parentNode); wizardKit.hideCatch(); wizardKit.hideLog(); if(!(/tutorials\/sample_list\.html/.test(witscript.toolbar.urlBar.getValue()))){ witscript.views.page.load("http://www.outwit.com/support/help/hub/tutorials/sample_list.html"); } witscript.views.page.display(); witscript.menutree.focus();

Here is the sample data

In previous tutorials about making scrapers, we have seen how to extract the population data and the images from this page.

wizardKit.hideCatch(); wizardKit.hideLog(); $("#p2Title").html("The Scraper"); $("#p2Text").html("This is the scraper we created in the Scraper tutorials."); wizardKit.say(this.parentNode); if(userSpace.waitOK) witscript.wait(1000); witscript.views.scrapers.display(); var currentScraper = views.scrapers.manager.currentAutomator(); if (currentScraper && currentScraper.automatorId == -1) { witscript.views.scrapers.editor.manageButton.click(); } if (!userSpace.scraperName || userSpace.scraperName != currentScraper.name) { witscript.views.scrapers.manager.createAutomator("Tutorial Advanced Scraper"); userSpace.scraperName = views.scrapers.manager.currentAutomator().name; witscript.views.scrapers.editor.url.setValue("http://www.outwit.com/support/help/hub/tutorials/sample_list.html"); } if(userSpace.waitOK) witscript.wait(3000,function(){return views.scrapers.source.isLoaded();}); if(userSpace.waitOK) witscript.wait(500); witscript.views.scrapers.editor.sourceSelector.static.click() witscript.views.scrapers.editor.display(); witscript.wait(100); witscript.views.scrapers.editor.datasheet.focus(); witscript.wait(100); witscript.views.scrapers.source.scrollToPercent(.4); witscript.wait(100); witscript.views.scrapers.source.findBar.toggleHighlight(false); witscript.views.scrapers.editor.datasheet.setCellValue(0, 1, true); witscript.views.scrapers.editor.datasheet.setCellValue(0, 2, "Flag"); witscript.views.scrapers.editor.datasheet.setCellValue(0, 3, "<li><img src=\""); witscript.views.scrapers.editor.datasheet.setCellValue(0, 4, "\""); witscript.views.scrapers.editor.datasheet.setCellValue(0, 6, "#BASEURL#\\0"); witscript.views.scrapers.editor.datasheet.setCellValue(1, 1, true); witscript.views.scrapers.editor.datasheet.setCellValue(1, 2, "City"); witscript.views.scrapers.editor.datasheet.setCellValue(1, 3, "width=\"22\">&nbsp;"); witscript.views.scrapers.editor.datasheet.setCellValue(1, 4, " ("); witscript.views.scrapers.editor.datasheet.setCellValue(1, 7, ","); witscript.views.scrapers.editor.datasheet.setCellValue(1, 8, "City,Country"); witscript.views.scrapers.editor.datasheet.setCellValue(2, 1, true); witscript.views.scrapers.editor.datasheet.setCellValue(2, 2, "Coordinates"); witscript.views.scrapers.editor.datasheet.setCellValue(2, 3, "("); witscript.views.scrapers.editor.datasheet.setCellValue(2, 4, "):"); witscript.views.scrapers.editor.datasheet.setCellValue(2, 7, ","); witscript.views.scrapers.editor.datasheet.setCellValue(2, 8, "Latitude,Longitude"); witscript.views.scrapers.editor.datasheet.setCellValue(3, 1, true); witscript.views.scrapers.editor.datasheet.setCellValue(3, 2, "Population"); witscript.views.scrapers.editor.datasheet.setCellValue(3, 3, "):"); witscript.views.scrapers.editor.datasheet.setCellValue(3, 4, "inhab.</li>"); witscript.views.scrapers.editor.datasheet.setCellValue(4, 1, true); witscript.views.scrapers.editor.datasheet.setCellValue(4, 2, "#repeat#Continent"); witscript.views.scrapers.editor.datasheet.setCellValue(4, 3, "<li>"); witscript.views.scrapers.editor.datasheet.setCellValue(4, 4, "<ol>"); witscript.views.scrapers.editor.saveButton.click(); witscript.menutree.focus();

Our goal is now to create a macro which will both extract this data and download the flag images to your hard disk.

wizardKit.say(this.parentNode); witscript.views.scrapers.editor.executeButton.click(); witscript.menutree.focus();
wizardKit.say(this.parentNode); witscript.views.page.display(); witscript.menutree.focus();

Getting the Images

For each city, the list includes the country flag as an SVG image. In some cases the image URLs are what you need. In others, you will want the image files themselves. For our example, let's say that we want to actually download these files.

wizardKit.say(this.parentNode); witscript.views.images.display(); var step = wizard.stepNumber(); witscript.menutree.focus();

To do this once, you simply need to go to the Images view, select them, right-click on the selection and choose 'Download'.

wizardKit.say(this.parentNode); var currentMacro = views.macros.manager.currentAutomator(); if (currentMacro && currentMacro.automatorId == -1) { witscript.views.macros.editor.buttons.manage.click(); } if (!userSpace.macroName || userSpace.macroName != currentMacro.name) { witscript.views.macros.manager.createAutomator("Tutorial Macro"); userSpace.macroName = views.macros.manager.currentAutomator().name; } witscript.views.macros.display(); witscript.menutree.focus();

If you know, however, that you will need to do this same task several times, or even regularly, the best way is to include both the scraper and the extraction of images in a macro.

wizardKit.say(this.parentNode); userSpace.MAU="outwit://www.outwit.com/support/help/hub/tutorials/sample_list.html" witscript.views.macros.editor.macroAsUrl.focus(); witscript.views.macros.editor.macroAsUrl.setValue(userSpace.MAU); witscript.menutree.focus();

A Macro That Does Both:
Scraping and Downloading

In the Macro Editor, you can define the desired settings for the whole application.

These settings are the same as the ones you find in the bottom panels of each view.

You can also define the exploration parameters and set the type of output you want for the extracted data.

wizardKit.say(this.parentNode); userSpace.MAU="outwit://www.outwit.com/support/help/hub/tutorials/sample_list.html&&(scraped=(export=html))" witscript.views.macros.editor.macroAsUrl.focus(); witscript.views.macros.editor.macroAsUrl.setValue(userSpace.MAU); witscript.menutree.focus(); if(userSpace.waitOK) witscript.wait(2000) if (userSpace.eyeCatcherOK) wizardKit.eyeCatcher(views.macros.editor.macroAsUrl,.5,.75,0,-20); //if (userSpace.eyeCatcherOK) wizardKit.eyeCatcher(views.macros.editor.extractors.scraped);

The Macro in a few clicks

Scraping: scrape the data and export it to html.

Each setting you choose is transcribed in real time in the "Macro as URL" textbox. Conversely, when changing the MAU, the controls are updated in real time.

wizardKit.say(this.parentNode); userSpace.MAU="outwit://www.outwit.com/support/help/hub/tutorials/sample_list.html&&(images=(selectColumn=Filename,selectValue=svg,download=true),scraped=(export=html))" witscript.views.macros.editor.macroAsUrl.focus(); witscript.views.macros.editor.macroAsUrl.setValue(userSpace.MAU); witscript.menutree.focus();

Images: download the SVG images.

In this case, selecting the images we want is easy: the common criterion is the filename extension. Each case is different and you may need to use other criteria like the size, the associated text, etc.

wizardKit.say(this.parentNode); userSpace.completeMAU="outwit://www.outwit.com/support/help/hub/tutorials/sample_list.html&&(images=(selectColumn=Filename,selectValue=svg,download=true),scraped=(export=html),data=(fileExists=overwrite),downloads=(fileExists=overwrite))" witscript.views.macros.editor.macroAsUrl.focus(); witscript.views.macros.editor.macroAsUrl.setValue(userSpace.completeMAU); witscript.menutree.focus(); //if (userSpace.eyeCatcherOK) wizardKit.eyeCatcher(views.macros.destination.extractedDataExistMenu,1.3,1.3,-10); if (userSpace.eyeCatcherOK) wizardKit.eyeCatcher(views.macros.editor.destination); if (userSpace.eyeCatcherOK) wizardKit.eyeCatcher(views.macros.editor.destination);

Overwrite the files that already exist on the hard disk.

We could have chosen to increment an index or add the time to the filename. We are leaving the default value for the destination folders, the extracted data and the downloaded files will go to the browser's current download folder.

wizardKit.say(this.parentNode); wizardKit.showLog(300); witscript.views.macros.editor.macroAsUrl.focus(); witscript.views.macros.editor.macroAsUrl.setValue(userSpace.completeMAU); witscript.menutree.focus(); witscript.views.macros.editor.execute.click();

Executing your Macro.

When you click on the Execute button in the Editor or in the Manager, the program does the exploration, extraction and export.

wizardKit.say(this.parentNode);

The results are being exported from the 'scraped' view and the files, downloded into the chosen folder.

Now that you have your macro, you can either run it manually when you want, using the execute button, or execute it at a given time or frequency, by including it in a job.

wizardKit.say(this.parentNode); witscript.menutree.focus(); userSpace.restoreOriginalPrefs(); if(witscript.version("2.1")){$(".owui-wizard-homelink").attr("style","color: #DFFFF9 !important; float:left;").html("More Tutorials")};

You are now ready to make your own macros.

This one was very simple, only extracting data from one page. Your macros can browse and dig through thousands of Web pages and extract very large amounts of data, but the principle will remain the same.

Stay tuned for more tutorials on the Hub's features.