Source: site.view [edit]
Function name: metacriticReviews
Arguments: movieName,movieUrl
Description:
Page type: webl
Render function:  
Module: sandbox

Page source:

var ElemByClass = fun(P, kind, className)
   var res = Select(Elem(P, kind),
        fun(a) 
           return ((a.class == className) ? false)
        end
       );
   return res
end;

var GetMetaScore = fun(P, scorekind)
   var res = Select(Elem(P, "img"),
        fun(a) 
           var alt = a.alt ? "";
           return Str_StartsWith(alt, scorekind)
        end
       );
   if (Size(res) == 1) then 
      var s = res[0].alt ? "";
      Str_Trim(Select(s, Size(scorekind), Size(s)))
   else
      return "?"
   end
end;

var P = GetURL(movieUrl) ? nil;
// var P = WubCall("metaPage", []);

var reviews = [];

if (P != nil) then
   every scoreAndReview in ElemByClass(P, "div", "scoreandreview") do
      var CriticScore = ElemByClass(P, "div", "criticscore") inside scoreAndReview;
      var Publication = ElemByClass(P, "span", "publication") inside scoreAndReview;
      var CriticName = ElemByClass(P, "span", "criticname") inside scoreAndReview;
      var Quote = ElemByClass(P, "div", "quote") inside scoreAndReview;

      if (Size(CriticScore) == 1) then
         var cs = Text(CriticScore[0]) ? "?";
         var pub = Text(Publication[0]) ? "?";
         var cn= Text(CriticName[0]) ? "?";
         var q = Str_Trim(Text(Quote[0])) ? "?";
         var url = Elem(P, "a") inside Quote[0] ? nil;
         var href = url[0].href ? "?";
         reviews = reviews + [ [. score = cs, criticname = cn, publication = pub,
           reviewurl = href, quote = q .] ];
      end
   end
end;

[. name = movieName,
   metascore = GetMetaScore(P, "Metascore:"),
   userscore = GetMetaScore(P, "User Score:"),
   reviews = reviews
.]