0

I have a question. It is possible to parse Javascript generated html tables? Because I tried with simple html dom, and I got a blank page for result every time.

Here is the parsed website:

<html>
<head>

<script src="informations.php" type="text/javascript" language="javascript"></script>


</head>
<body>

<script language="javascript" type="text/javascript">
<!--

// Draw table from 'jsData' array of objects
function drawTable(tbody) {
    var tr, td;
    tbody = document.getElementById(tbody);
    // loop through data source
    for (var i = 0; i < data.length; i++) {
        tr = tbody.insertRow(tbody.rows.length);
        tr.setAttribute("class", "f1");
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = data[i][1];
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = data[i][2];
td = tr.insertCell(tr.cells.length);
        td.setAttribute("align", "center");
        td.innerHTML = data[i][3];
        td = tr.insertCell(tr.cells.length);
        td.setAttribute("align", "center");
        td.innerHTML = data[i][4];
td = tr.insertCell(tr.cells.length);
        td.setAttribute("align", "center");
        td.innerHTML = data[i][5];

    }
}

//-->
</script>


<table>
<tr>
<td><h2>Informations</h2></td>
</tr>
</table>
<table class="sortable">
<thead>
<tr>
    <th>Name</th>
    <th>Information</th>
<th>Birthday</th>
<th>Postcode</th>
<th>Job</th>
</tr>
</thead>
<tbody id="FData"></tbody>
</table>

<script language="javascript" type="text/javascript">
drawTable("FData");
</script>
</body>
</html>

I have no problem with classic tables, but with js generated tables I got blank page for result everytime. What is the solution?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Terminus
  • 15
  • 6

1 Answers1

0

try this code in your JS function.

// Find a element with id="myTable":

var table = document.getElementById("myTable");

// Create an empty element and add it to the 1st position of the table:

var row = table.insertRow(0);

// Insert new cells ( elements) at the 1st and 2nd position of the "new" element:

var cell1 = row.insertCell(0); var cell2 = row.insertCell(1);

// Add some text to the new cells:

cell1.innerHTML = "NEW CELL1"; cell2.innerHTML = "NEW CELL2";

Awaissoft
  • 41
  • 1
  • 1
  • 6
  • I don't understand this. If I put this extra table before my table then my table will be able to parse? I see just your code will put an extra table before my table, not? – Terminus May 26 '15 at 08:18
  • please assign ID in your table tag. like this: ``
    – Awaissoft May 27 '15 at 00:48