This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <table> | |
| <tr> | |
| <th>Pet 1</th> | |
| <th>Pet 2</th> | |
| </tr> | |
| <tr> | |
| <td>Dog</td> | |
| <td>Cat</td> | |
| </tr> | |
| </table> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require("axios"); | |
| const cheerio = require("cheerio"); | |
| const ObjectsToCsv = require("objects-to-csv"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async function html_scraper() { | |
| const response = await axios('https://datatables.net/examples/styling/display.html'); | |
| console.log(response.status) | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const html = await response.data; | |
| const $ = cheerio.load(html); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const allRows = $('table.display &gt; tbody &gt; tr'); | |
| console.log(allRows.length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| allRows.each((index, element) =&gt; { | |
| const tds = $(element).find('td'); | |
| const name = $(tds[0]).text(); | |
| const position = $(tds[1]).text(); | |
| const office = $(tds[2]).text(); | |
| const age = $(tds[3]).text(); | |
| const startDate = $(tds[4]).text(); | |
| const salary = $(tds[5]).text(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| employeeData = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| employeeData.push({ | |
| 'Name': name, | |
| 'Position': position, | |
| 'Office': office, | |
| 'Age': age, | |
| 'Start Date': startDate, | |
| 'Salary': salary, | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const csv = new ObjectsToCsv(employeeData); | |
| await csv.toDisk('./employeeData.csv') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const axios = require("axios"); | |
| const cheerio = require("cheerio"); | |
| const ObjectsToCsv = require("objects-to-csv"); | |
| employeeData = []; | |
| (async function html_scraper() { | |
| const response = await axios('https://datatables.net/examples/styling/display.html') | |
| const html = await response.data; | |
| const $ = cheerio.load(html); |
OlderNewer