How do you import simple data from a webpage using Javascript -


the problem have run seems has simple answer. want have website simple task of grabbing piece of text webpage.

i want code like...

var str = textfromwebpage; 

the text want "grab" on http://dasd-sharepoint.dasd.org/schools/stemacademy/pages/default.aspx

if on page (try control f , search current date, ex: "may-9-2013:") list of next 5 dates. want take list , use in variables in javascript.

so prefered end result be

var str = new array("may-9-2013: “f” day", "may-10-2013: “g” day", "may-13-2013: “h” day", "may-14-2013: “i” day", "may-15-2013: “j” day", "may-16-2013: “k” day"); 

purpose: school i'm checking time. instead of doing math make quick little program @ current time vs time current class ends. in school have different "letter days" means class lengths different on different days. letter days based on 12 day cycle means. monday through friday a-e mean following week monday f-j. not mention if there snow day or day off. instead of using calendar figured there has way can grab data district webpage , utilize in code automatically check letter day is.

thanks , help!

here code i'm doing...

<!doctype html> <html>      <head>         //<link rel="stylesheet" type="text/css" href="graphics.css">         <script>             //==========|  data  |==========             //these array lists contain times class periods start, end, , title             var ptest = new array("starts: 07:25 ends: 15:00 title: testing", "starts: 07:25 ends: 30:00 title: testing");             var p14 = new array("starts: 07:25 ends: 09:00 title: pd: 1", "starts: 09:04 ends: 10:34 title: pd: 2", "starts: 10:38 ends: 11:08 title: lunch", "starts: 11:12 ends: 12:42 title: pd: 3", "starts: 12:46 ends: 14:23 title: pd: 4");             var p17 = new array("starts: 07:25 ends: 08:20 title: pd: 1", "starts: 08:24 ends: 09:14 title: pd: 2", "starts: 09:18 ends: 10:08 title: pd: 3", "starts: 10:12 ends: 11:02 title: pd: 4", "starts: 11:06 ends: 11:36 title: lunch", "starts: 11:40 ends: 12:30 title: pd: 5", "starts: 12:34 ends: 13:24 title: pd: 6", "starts: 13:28 ends: 14:23 title: pd: 7");             var p57 = new array("starts: 07:25 ends: 09:00 title: pd: 5", "starts: 09:04 ends: 10:34 title: pd: 6", "starts: 10:38 ends: 11:08 title: lunch", "starts: 11:12 ends: 12:42 title: pd: 7", "starts: 12:46 ends: 13:36 title: advisory", "starts: 13:40 ends: 14:23 title: seminar");             //---------------------------------              //==========|  variables  |==========             var input = p17; //what set of data use             var currentslot = 0; //what current period             var on = false; //if current school day if on             //---------------------------------              //==========|  actions  |==========             window.onload=function() {                 setinterval(function() {refresh();}, 1); //loop             }              //---------------------------------               //==========|  core functions  |==========             function refresh() {                 display();                 updateclock();             }              function display() {                 var currenttime = gettime();                 var timeinsec = ((parseint(currenttime.slice(0,2)))*3600)+((parseint(currenttime.slice(3,5)))*60)+(parseint(currenttime.slice(6,8)));                  if (currentslot >= input.length) {over = true;}                 if (over == false) {                     var data = input[currentslot];                     var nextslot = input[currentslot + 1];                      var pdendtime = ((parseint(data.slice(20,23)))*3600)+((parseint(data.slice(23,25)))*60);                      var pdstart = data.slice(8,13);                     var pdend = data.slice(20,25);                     var pdtitle = data.slice(32,data.length);                      if (nextslot!==undefined) {                         var npdstart = nextslot.slice(8,13);                         var npdend = nextslot.slice(20,25);                         var npdtitle = nextslot.slice(32,nextslot.length);                     }                      var timeleft = pdendtime - timeinsec;                     var hleft = math.floor(timeleft / 3600);                     var mleft = math.floor(timeleft / 60);                     var sleft = math.floor(timeleft % 60);                      if (hleft > 0) {mleft = mleft - (hleft*60);}                      hleft = add0(hleft);                     mleft = add0(mleft);                     sleft = add0(sleft);                      if (timeinsec > pdendtime) {currentslot++;}                      document.getelementbyid("display").innerhtml = pdtitle+" ends @ "+pdend+", in "+hleft+":"+mleft+":"+sleft;                 }                 else {document.getelementbyid("display").innerhtml = "school over!";}             }              //---------------------------------              //==========|  misc functions  |==========               function gettime() {                 var clock = new date();                 var h = clock.gethours();                 var m = clock.getminutes();                 var s = clock.getseconds();                  h = add0(h);                 m = add0(m);                 s = add0(s);                  return h+":"+m+":"+s;             }              function updateclock() {                 document.getelementbyid("clock").innerhtml = gettime();             }              function add0(i) {                 if (i < 10) {                      = "0"+i;                 }                 return i;             }              function changeinput(newinput) {                 input = newinput;                 currentslot = 0;             }             //---------------------------------         </script>      </head>     <body>         <p id="clock" class="textcenter"></p>         <p id="display" class="textcenter"></p>         <p class="textcenter">         <input type="button" onclick="changeinput(p14)" value="1-4 block">         <input type="button" onclick="changeinput(p17)" value="1-7 normal">         <input type="button" onclick="changeinput(p57)" value="5-7 block">         </p>     </body> </html> 

i want automatically check letter day don't have have users click buttons. example a-day = 1-7, b-day = 1-4, c-day = 1-7, d-day = 5-7

if doing website, best bet use secondary page on website uses php or asp, or other server side programming language grab page , return contents, while you're @ can use powerful regular expressions in server side language , return json object of need. real problem here can't go yoursite.com dasd-sharepoint.dasd.org/schools/stemacademy/pages/default.aspx not possible in traditional java script environment.

the reason conclusion when executing xmlhttprequest (xhr) browsers designed not access website. , if were, technically webserver should deny access via xhr domain, known cross domain request , not natively possible within javascript.

using secondary page go fetch contents of this, far more efficient , require no add-on use function/website. gives precise control on functionality , easy portability hosts. allows client able access page , utilize functionality.

using add-ons never proper way something, there better easier way.

now onto html5 goodies doing website

if have in headers sent remote host, can have them send "access-control-allow-credentials: true" header allow xmlhttprequest2 aka cors requests process, can see more information regarding subject @ following url: http://www.html5rocks.com/en/tutorials/cors/

unfortunately don't have experience cors don't have helpful how-to's or else, pretty similar typical ajax request supports cross domain long remote party allows (control-allow-credentials: true) , system formated of course doesn't leave lot of help, gives information making proper system.

if doing on same website (so different page of same website/domain dasd-sharepoint.dasd.org there easy ways information. parsing through information on web page can difficult process when getting started should not terrible. write more on subject later today have going.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -