Class: PageHTML

PageHTML()

A class representing HTML pages.

Constructor

new PageHTML()

Source:

Methods

clear() → {null}

A method to clear the array of the dom property of the class.

Source:
Returns:
Type
null

close()

Closes the browser instance of Puppeteer and sets the page and browser properties of the PageHTML class to null.

Source:

content(index, elementString) → {Array.<{elementText: string, nodeName: string, outerHTML: string, innerHTML: string, parentElement: string}>}

A method that returns a content object containing the text content and other relevant parameters for an HTML element.

Parameters:
Name Type Description
index number | Array.<number>

The index of the dom property to perform this method on. This may be a single number or an array of numbers. If left undefined it will apply to all indexes.

elementString string
Source:
Returns:

an array of element objects.

Type
Array.<{elementText: string, nodeName: string, outerHTML: string, innerHTML: string, parentElement: string}>
Example
```javascript
// create the PageHTML class.
let pHtml = new PageHTML();

// load the webpage.
await pHtml.get('https://www.whatsmyua.info/');

// close the connection.
pHtml.close();

// return the list element with id rawUa.
// setting index to 0 returns the 0th JSDOM element in the pHtml.dom property.
// additionally we set the array index to 0 to confirm we only want the first instance.
let userAgentDetected = pHtml.content('li#rawUa',0)[0];

console.log(userAgentDetected);
```
returns the string user agent detected by www.whatsmyua.info

(async) get(url) → {jsdom.JSDOM}

A function that retrieves data from a webpage.

Parameters:
Name Type Description
url string

The target url from which to grab data.

Source:
Returns:

The document object model (dom).

Type
jsdom.JSDOM

A method that returns a links object containing relevant information to any href elements in the instance of a JSDOM class.

Parameters:
Name Type Description
index number

The index of the dom property to perform this method on. This may be a single number or an array of numbers. If left undefined it will apply to all indexes.

Source:
Returns:

an array of link objects.

Type
Array.<{href: string, nodeName: string, outerHTML: string, innerHTML: string, parentElement: string}>
Example
```javascript

// create the PageHTML class.
let pHtml = new PageHTML();

// grab the webpage content.
await pHtml.get('https://en.wikipedia.org/wiki/List_of_Formula_One_Grand_Prix_winners');

// close the webpage.
pHtml.close();

// setting index to 0 returns the link objects for the 0th JSDOM element in the pHtml.dom property.
// additionally we set the array index to 2 to confirm we only want the third link.
let links = pHtml.links(0)[2];
console.log(tables);
```
returns the third href link from the webpage as a link object.

tables(index) → {Array.<string>}

A method to return all tables present in an instance of the JSDOM class.

Parameters:
Name Type Description
index number

The index of the dom property to perform this method on. This may be a single number or an array of numbers. If left undefined it will apply to all indexes.

Source:
Returns:

an array of arrays representing rows and columns of an html table.

Type
Array.<string>
Example
```javascript

// create the PageHTML class.
let pHtml = new PageHTML();

// grab the webpage content.
await pHtml.get('https://en.wikipedia.org/wiki/List_of_Formula_One_Grand_Prix_winners');

// close the webpage.
pHtml.close();

// setting index to 0 returns the tables for the 0th JSDOM element in the pHtml.dom property.
// additionally we set the array index to 1 to confirm we only want the second table.
let links = pHtml.tables(0)[1];
console.log(tables);
```
returns the second html table from the webpage as an array of arrays.