Answer the question
In order to leave comments, you need to log in
How to parse html page to js?
I'm getting an HTML page that has several tables. I need to get a JSON file like this:
{
sheets:
[
{
name: "table1",
data: [
{
row: 0,
raw: [
{ col: 0,
text: "text"
class: "s28"
},
{ col: 1 ,
text: "text"
class: "s28"
},
{ col: 2,
text: "text"
class: "s28"
},
]
},
{
row: 1,
raw: [
{ col: 0,
text: "text"
class: "s28"
},
{ col: 1,
text: "text"
class: "s28"
},
{ col: 2,
text: "text"
class: "s28"
},
....
]
},
...
]
}
]
]
}
I split the code into an array consisting of tables using regular. Can anyone point me in the right direction?
Answer the question
In order to leave comments, you need to log in
To work with the DOM in js, it's better to use jquery and not suffer. Then you select, for example, all tables and sort through them, forming an array. Well, then you do it from a JSON array. More or less like this:
$('table').each(function(iTable, thisTable) {
...
$(this).find('tr').each(function(iRow, thisRow) {
...
});
});
What the hell is "regular"? Everything is already parsed in the browser, the document with all its contents is already a parsed page, take everything you need from it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question