how to convert scraped data to table

82 Views Asked by At

I have a basic question, I am modifying a module for MagicMirror. So, what I have is a module that scrapes data from a site, trying to get a prayer time from a site.

The code basically gives me one column of data, what I need is the data to be on a table as the first parsed data on row 1 and the second parsed data on row 2 and the ability to create style for that table or add an image and some calculation like time left for next prayer time, and highlight the next prayer time.

I know it's a lot of questions, but I would like to start with the first one: how to convert these data into a table?

so this is the results that am getting on the first pic, and the results that i need is on the second picture, so create a table, and add a rows, and replace the heading on the row 2 with the headings on row 1or just add row 1 on top, please note that i the informations on row 1 am not getting it needs to be added by me, many thanks again for your help Pic 1 https://ibb.co/9ZGkYWj

Pic 2 https://ibb.co/Zhr5j6r

my code:

{
getDom: function() {


        var wrapper=document.createElement("table");

    if(this.content.length>0){

        for(i=0;i<this.content.length;i++) {

            var w = document.createElement("div");

            var n = this.content[i]

            w.innerHTML=n;

            wrapper.appendChild(w)


        }
    }
    else{
        wrapper.innerText=this.message
    }
    // tell MM this is our content to add to the MM dom
    return wrapper;
}

});
1

There are 1 best solutions below

2
dnaz On
{
getDom: function() {


        var wrapper=document.createElement("table");

    if(this.content.length>0){
        var w1 = document.createElement("tr");
        var w2 = document.createElement("tr");
        var arr = [w1,w2];

        for(i=0;i<this.content.length;i++) {



            var n = this.content[i]

            let vrb = "<td>"+n+"</td>";

            arr[i % 2].append(vrb);


        }
        wrapper.appendChild(w)
    }
    else{
        wrapper.innerText=this.message
    }
    // tell MM this is our content to add to the MM dom
    return wrapper;
}

If I understood clearly, try this.