Source: site.view [edit]
Function name: cmdGetJobSalaries
Arguments:
Description: Retrieve list of jobs and average salary ranges
Page type: webl
Render function:  
Module: skillsrank

Page source:

var P = GetURL("http://move.salary.com/salarywizard/layoutscripts/swzl_newsearch.asp") ? nil;

var ok = true;
var writer = Wub_NewLuceneIndex("jobsalaries", true) ? ok = false;

var res = [. .];

if (P != nil) then

   var Options = Elem(P, "option") inside Elem(P, "select")[0];
   
   // every option in Options do
     var option = Options[0];
     var category = Str_Trim(Text(option));

      var url = "http://move.salary.com/salarywizard/layoutscripts/swzl_titleselect.asp?narrowdesc=" + 
                Url_Encode(category) + "&narrowcode=" + option.value + "&zipcode=&metrocode=&x=43&y=4";
     
      var P2 = GetURL(url) ? nil;


      while P2 != nil do

           var Links = Elem(P2, "a") contain Pat(P2, "Base Salary Range");
           every link in Links do
              // var link = Links[5];

              url = link.href ? "";
              url = Wub_ReplaceAll(url, "pagenumber=1", "pagenumber=2");
              var P3 = GetURL(url) ? nil;
              if P3 != nil then

                 var Table = Elem(P3, "table") directlycontain Pat(P3, "25th Percentile");

                 if Size(Table) > 0 then
                    var jobinfo = [. .];
                    var TR = Elem(P3, "tr") inside Table[0];
                    var Row = TR directlycontain Pat(P3, "25th Percentile");
                    if (Size(Row) > 0) and (Size(TR) > 2) then
                       var TD = Elem(P3, "td") inside Row[0];
                       var title =Str_Trim(Text(TD[0]));

                      TD = Elem(P3, "td") inside TR[Size(TR) - 2];
                      if (Size(TD) > 4) then

                          var doc = Wub_NewLuceneDocument();

                          ok = ok and Wub_AddLuceneField(doc, "category", category, true, true);
                          ok = ok and Wub_AddLuceneField(doc, "jobtitle", title, true, true);
                          ok = ok and Wub_AddLuceneField(doc, "low", Str_Trim(Text(TD[1])), true, true);
                          ok = ok and Wub_AddLuceneField(doc, "med", Str_Trim(Text(TD[2])), true, true);
                          ok = ok and Wub_AddLuceneField(doc, "high", Str_Trim(Text(TD[3])), true, true);

                          ok = ok and Wub_AddLuceneDocument(writer, doc);
                      else
                          res["error"] := "TD not > 4: " + ToString(Size(TD))
                      end
                    else
                        res["error"] := "TR not > 2: " + ToString(Size(TR)) + " " + ToString(Size(Row))
                    end;
                 else
                    res["error"] := "Table not > 0: " + ToString(Size(Table))
                 end;  // If Size Table > 0
 
             else
                 res["error"] := "P3 == nil: " + url
 
             end;  // P3 not null


          end;   // every  link in links

          // Click on "Next" link
          var A = Elem(P2, "a") contain Pat(P2, "Next");
          if Size(A) > 0 then
               P2 = GetURL(A[0].href) ? nil;
               // P2 = nil;
          else
               P2 = nil
          end

  end;  // while

   // end;  // every option in options

end;  // if P != nil


ok = ok and Wub_CloseLuceneIndex(writer);

ok;