Skip to content

Instantly share code, notes, and snippets.

@jasp402
Last active March 19, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasp402/fe904eb707ec627c58271a7131c236d4 to your computer and use it in GitHub Desktop.
Save jasp402/fe904eb707ec627c58271a7131c236d4 to your computer and use it in GitHub Desktop.
JavaScript - Get content Table and merge with head
let headTable = c.TABLE_HEAD;
let table = $$(c.TABLE)
.map(tr=>tr.getHTML().match(c.REGEX_TD)
.map(x=>x.indexOf('View EOB')===-1
? x.replace(c.REGEX_TAGS,'')
: x.match(c.REGEX_ONCLICK)
.map(x=>x.replace(/onclick=|"/ig,''))[0]));
let result = table.map((el, idx)=> {
let obj = {id: idx+1}; headTable.map((h,i)=>obj[headTable[i]] = el[i]);
return obj;
});
/**Para unir los resultados de 2 tablas en 1 solo**/
// let merge = resultTableFlatt.map(function (item, index) {
// console.log('response:>>', resultResponseFlatt[index]);
// let objTemp = Object.assign(item, resultResponseFlatt[index]);
// return objTemp;
// });
REGEX_TD : /<.[^>].*?<\/td>/g,
REGEX_TAGS : /<(.|\n)*?>/g,
REGEX_ONCLICK : /(onclick=\").*?\"/g,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment