Source: site.view [edit]
Function name: findBooksBy
Arguments: author
Description: A command to find books by an author -> Example input: author='Michael Dahl'
Page type: webl
Render function:   tlidRender
Module: global

Page source:

var P;
var tmp1;
var context;

context = NLUtil_InitContext();

//|| go to http://www.amazon.com
context = NLUtil_GetUrl(context, "http://www.amazon.com", nil, nil);
P = NLUtil_GetContext(context, `P`);

//|| find all links that contain Books
P = NLUtil_GetContext(context,`P`);
context = NLUtil_SetContext(context,`a`, Elem(P, `a`)  contain Pat(P, `(?i)` + `Books`));

//|| select first link
context = NLUtil_SetContext(context,NLUtil_LastType(context), Select(NLUtil_LastSet(context),0,1));

//|| click it
context = NLUtil_clickLink(context);
P = NLUtil_GetContext(context, `P`);

context = NLUtil_SetContext(context, `P`, P);

//|| find all forms
P = NLUtil_GetContext(context,`P`);
context = NLUtil_SetContext(context,`form`, Elem(P, `form`) );

//|| select first form
context = NLUtil_SetContext(context,NLUtil_LastType(context), Select(NLUtil_LastSet(context),0,1));

//|| fill in field-keywords with the author
context = NLUtil_SetField(context, "field-keywords", author);

//|| submit form
context = NLUtil_submitForm(context);
P = NLUtil_GetContext(context, `P`);

//|| return the page

if Size(OPTIONALARGS) == 0 then
   NLUtil_LastValue(context);
else
   context;
end;