P
P
Pytniza2019-04-05 09:36:16
JavaScript
Pytniza, 2019-04-05 09:36:16

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

2 answer(s)
A
Aricus, 2019-04-05
@Pytniza

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) {
    ...
  });
});

M
Moses Fender, 2019-04-05
@mosesfender

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 question

Ask a Question

731 491 924 answers to any question