Source: site.view [edit]
Function name: searchZocDoc
Arguments: specialty,zip,insurancePlan,insuranceCarrier,gender,language,children
Description:
Page type: webl
Render function:  
Module: sandbox

Page source:

var getDivByClass = fun(P, elt, className) 
   var E = Elem(P, "div") inside elt;
   every d in E do
     var c = d.class ? nil;
     if (Str_IndexOf(className, c) >= 0 then
        return d
     end
   end;
   return nil
end;
     

var getTimeData = fun(s)
   var ss = `search_app.response = {`;
   var i = Str_IndexOf(ss, s);
   if i > 0 then
      s = Select(s, i + Size(ss)-1, Size(s))
   end;
  
   i = Str_IndexOf(`if (ids.length > 0)`, s);
   if (i > 0) then
      s = Str_Trim(Select(s, 0, i-1));
      if (Str_EndsWith(s, ";")) then
         s = Select(s, 0, Size(s)-1);
      end
   end;
  
   s;
end;


var res = [];
var P = WubCall("sandbox.callZocDoc", [specialty, zip, insurancePlan, insuranceCarrier, gender, language, children]);
P = WubCall("sandbox.callZocDoc", [specialty, zip, insurancePlan, insuranceCarrier, gender, language, children]);
var E = Elem(P, "div");

every d in E do
  
  var c = d.class ? nil;
  
  if (c != nil and Str_IndexOf("js-prof-row-container", c) >= 0) then
     
     var drInfo = [. .];
     
     var nm = getDivByClass(P, d, "ch-prof-row-photo-container");
     if (nm != nil) then
        var img = Elem(P, "img") inside nm;
        if Size(img) > 0 then     
           drInfo.photo := img[0].src;
        end;
     end;

     nm = getDivByClass(P, d, "docName");
     if (nm != nil) then    
        var a = Elem(P, "a") inside nm;
        if Size(a) > 0 then
           drInfo.name := Str_Trim(Text(a[0]));
        else
           drInfo.name := Str_Trim(Text(nm));
        end;
        var span = Elem(P, "span") inside nm;
        if Size(span) > 0 then
           drInfo.title := Str_Trim(Text(span[0]));
        end
     end;

     nm = getDivByClass(P, d, "docAddress1");
     if (nm != nil) then            
        drInfo.street := Str_Trim(Text(nm));
     end;

     nm = getDivByClass(P, d, "docAddress2");
     if (nm != nil) then            
        var addr = Str_Match(Str_Trim(Text(nm)), `(.+),\s+(\w+)\s+(\d+)`);
        if (addr != nil) then
           drInfo.city := addr[1];
           drInfo.state := addr[2];
           drInfo.zip := addr[3]
        end
     end;

     nm = getDivByClass(P, d, "profSpecTitle");
     if (nm != nil) then            
        drInfo.specialty := Str_Trim(Text(nm));
        drInfo.specialtyCode := nm["data-spectialty"]
     end;

     nm = getDivByClass(P, d, "view-profile-button");
     if (nm != nil) then    
        var a = Elem(P, "a") inside nm;
        if Size(a) > 0 then
           drInfo.profileLink := a[0].href;
        end;
     end;
     
     nm = getDivByClass(P, d, "insuranceBody");
     if (nm != nil) then            
        drInfo.insurance := Str_Trim(Text(nm));
     end;

     nm = getDivByClass(P, d, "docRating");
     if (nm != nil) then   
        every rd in Elem(P, "div") inside nm do
           c = rd.class ? nil;
           if Str_IndexOf("rating", c) >= 0 then
              c = Str_Trim(c);
              c = Select(c, Size(c)-3, Size(c)-2) + "." + Select(c, Size(c)-1, Size(c));
              drInfo.rating := c;
           end;
        end;
     end;
     
     nm = getDivByClass(P, d, "comment-text");
     if (nm != nil) then 
        var txt = Wub_ReplaceAll(Str_Trim(Text(nm)), `"`, "'");
        txt = Wub_ReplaceAll(txt, "\n", " ");     
        drInfo.review := txt
     end;
     
     res = res + [drInfo]
  end
  
end;
  
NewPage(WubCall("toJSON", [res]), "text/plain");