pagehtml
Version:
A tool to grab and process a website's html.
79 lines (55 loc) • 2.38 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: utils/makeTable.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: utils/makeTable.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Takes an instance of the JSDOM class and returns all html tables as an array of arrays.
* @param {jsdom.JSDOM} dom The document object model, an instance of the JSDOM class.
* @returns {string[]} tables
*/
function makeTable(dom) {
headers = Array.prototype.map.call(dom.window.document.querySelectorAll('table'), table =>
Array.prototype.map.call(table.querySelectorAll('thead tr'), tr =>
Array.prototype.map.call(tr.querySelectorAll('th'), th =>
th.textContent.trim())));
body = Array.prototype.map.call(dom.window.document.querySelectorAll('tbody'), tbody =>
Array.prototype.map.call(tbody.querySelectorAll('tr'),tr =>
Array.prototype.map.call(tr.querySelectorAll('td, th'), td =>
td.textContent.trim())));
tables = [];
for (let i = 0; i < headers.length; i++) {
content = headers[i].concat(body[i]);
tables.push(content);
}
return tables;
}
module.exports = makeTable;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="PageHTML.html">PageHTML</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getElementText">getElementText</a></li><li><a href="global.html#getLinks">getLinks</a></li><li><a href="global.html#makeTable">makeTable</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Wed Feb 05 2025 14:23:55 GMT-0800 (Pacific Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>