Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   2 var page = require('webpage').create();
  2.   3 var fs   = require('fs');
  3.   4
  4.   5 console.log(phantom.injectJs('./jquery.min.js'));
  5.   6
  6.   7 var URL = 'http://data.bls.gov/location_quotient/ControllerServlet';
  7.   8 var MSA_options = new Array();
  8.   9
  9.  10 page.onLoadFinished = function(status){
  10.  11   // If the page did not load successfully:
  11.  12   if (status !== 'success')
  12.  13     phantom.exit();
  13.  14    
  14.  15   // If the page did load successfully:
  15.  16
  16.  17   var content = page.content;
  17.  18   var options = $('select[name|="analysis_area1"]',content)[0].options;
  18.  19   console.log(options.length);
  19.  20  
  20.  21   $(options).each(function(index){
  21.  22     var x = options[index];
  22.  23     if(x.text.indexOf('MSA') >= 0){
  23.  24       MSA_options.push([$.trim(x.text),index]);
  24.  25     }
  25.  26   });
  26.  27
  27.  28   beginMiningOperation();
  28.  29
  29.  30
  30.  31 }
  31.  32
  32.  33 page.open(URL);
  33.  34
  34.  35 function beginMiningOperation(){
  35.  36   actionPage = require('webpage').create();
  36.  37   var finishedLoading = function(status){
  37.  38     if(status!=='success')
  38.  39       console.log('PageFailedToLoad!');
  39.  40  
  40.  41     actionPage.render('datapage.png');
  41.  42  
  42.  43     phantom.exit();
  43.  44   }
  44.  45    
  45.  46   var subarr = MSA_options.slice(0,3);
  46.  47   //for(var i;i<MSA_options.length;i += 3){
  47.  48     actionPage.open(URL,function(){
  48.  49       actionPage.onLoadFinished = finishedLoading;
  49.  50       console.log(subarr);
  50.  51       actionPage.evaluate(function(subarr){
  51.  52         $('select[name|="analysis_area1"]')[0].selectedIndex = subarr[0][1];
  52.  53         $('select[name|="analysis_area2"]')[0].selectedIndex = subarr[1][1];
  53.  54         $('select[name|="analysis_area3"]')[0].selectedIndex = subarr[2][1];
  54.  55         $('input[name|="Sector"]')[0].checked = true;
  55.  56         $('#submit')[0].click();
  56.  57       },subarr);
  57.  58
  58.  59     });
  59.  60   //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement