Help: Get data from url and write to table - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help: Get data from url and write to table

Hi everyone,

First, I am not a programmer so be gentile. I need some help getting data from a url and placing it into a table. I am trying to get the daily threshold securities list that is published daily on the nasdaq site. The data published today is for yesterday's threshold securities. The url changes everyday according to the date eg: http://www.nasdaqtrader.com/dynamic/symdir/regsho/nasdaqth20100222.txt. The script that I managed to hack together does get the correct url everyday, but I am unable to insert the data into a dynamically created table. Here is what I have so far:
[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


ShoList



//create the Cross-browser XMLHttpRequest object
function getFile(pURL,pFunc) {
if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
xmlhttp=new XMLHttpRequest();
eval('xmlhttp.onreadystatechange='+pFunc+';');
xmlhttp.open("GET", pURL, true); // leave true for Gecko
xmlhttp.send(null);
} else if (window.ActiveXObject) { //IE
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
if (xmlhttp) {
eval('xmlhttp.onreadystatechange='+pFunc+';');
xmlhttp.open('GET', pURL, false);
xmlhttp.send();
}
}

}

function makeTable() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
var tmpArr=xmlhttp.responseText.split('
');
var out='';
var tmp;
var val;
var txt;
var strText;
for (var idx=0;idx'+tmpArr[idx]+'';*/
strText= '';
for (var intTmp=0;intTmp'+txt+'';
}
}
/*{
if (intTmp'+txt+'';
}
else
txt = tmp[intTmp].replace('"','')
txt=''
strText= strText + '';
parent.shoDate=txt
}
}*/
out += strText + '';
}
out += '
'+txt+'
';
document.getElementById('theList').innerHTML=out;
}
}

}



function getFileUrl(){
/*First, get the current date*/
var currentTime = new Date();

/*because shoLists are published only at midnight during the workweek, we must subtract 1 from the day
In the case of Sunday, we subtract two, and Monday, subtracdt 3 in order to get Friday's list*/
var intNB = 1
if(currentTime.getDay() == 0)
{
intNB=2;
}
else if(currentTime.getDay() == 1)
{
intNB = 3;
}
else
{
intNB = 1;
}

/*We now need to subtract the number from the day to get the right date (Year, month, and day)*/
var day = currentTime.getDate() - intNB;
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();

/*If the day is less than ten, we must add a 0 to make the day a two digit number*/
if (day







Loading...



[/code]

Comments

  • mac_doggiemac_doggie Posts: 488Member
    I don't think ajax will work cross domain, so you'll need to call a script on your own website to get the data, or you might be able to use an iframe, but I think then you can't manipulate it's contents if it's on another domain as well...

    To answer the question of reading data from the url and placing it in a table you could do something like this:

    [code]
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">






    function createTable() {
    var params = document.location.search.substr(1).split('&');
    var table = document.createElement('table');
    var tbody = document.createElement('tbody');
    table.appendChild(tbody);
    for(var i=0;i




    // this script strips everything after ? and puts the fields in the first td and the value in the second td
    //
    createTable();



    [/code]
    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...
  • littlemonstalittlemonsta Posts: 2Member
    Hi mac, Thanks for trying but I still can't get the info from the URL to a table. As I said before I am not a programmer and there are a lot of things that I just don't understand, I'm trying to learn. The script that I posted gives me the correct URL daily, but it writes the URL to the page instead of taking the contents of that URL and creating a table with them.
  • mac_doggiemac_doggie Posts: 488Member
    if you have the URL in your page, is it inside a div tag like:


    ??

    If this is the case you can use javascript to grab that line of text and split it up into pieces. You can use my example, but replace the document.location.search with documentGetELementById('contentsofothersite').innerHTML

    where contentsofothersite is the ID of the div element that the URL is in.

    hope this helps you out...
    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...
Sign In or Register to comment.