-1

I am trying to parse a table from a website. Which is like : enter image description here

Desired result I want is something like that : enter image description here

How to achieve it.

Table is made up of simple <tr> <td> tags and used rowspan and colspan for spacing.

How to achieve it in PHP or JS?

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
Amar
  • 420
  • 3
  • 14
  • What have you tried? Please edit your question and include the relevant source code to your question. Thank you. – NewToJS Aug 05 '17 at 13:13

1 Answers1

0

in PHP, use DOMDocument.

foreach((@DOMDocument::loadHTML($html))->getElementsByTagName("tr") as $tr){
    foreach($tr->getElementsByTagName("td") as $td){
        var_dump($td->textContent);
    }    
}

in Javascript, use DOMParser.

var doc=(new DOMParser()).parseFromString(html,"text/html");
var all=doc.querySelectorAll("tr > td");
for(var i=0;i<all.length;++i){
    console.log(all[i].textContent);
}
hanshenrik
  • 19,904
  • 4
  • 43
  • 89