This file contains 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
{ | |
"products": [ | |
{ | |
"name": "Truman Grade", | |
"description": "Detect harmful websites instantly", | |
"image": "https://ph-files.imgix.net/bfc7e122-b276-4907-9cad-9f9d370ad90f?auto=format&auto=compress&codec=mozjpeg&cs=strip&w=80&h=80&fit=crop", | |
"upvotes": "129", | |
"comments": "8" | |
}, | |
{ |
This file contains 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
let axios = require('axios'); // HTTP client | |
let cheerio = require('cheerio'); // HTML parsing package | |
let jsonframe = require('jsonframe-cheerio'); // a cheerio plugin I designed | |
let fs = require('fs'); // is included in node.js - you don't need to install it | |
axios.get('https://www.producthunt.com') | |
.then((response) => { | |
if(response.status === 200) { |
This file contains 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
let axios = require('axios'); | |
axios.get('https://www.producthunt.com') // HTTP request to https://www.producthunt.com | |
.then((response) => { // Success case | |
if(response.status === 200) { // If HTTP Response is 200 - All good | |
let html = response.data; // Setting the reponse.data to html | |
} // to make things clear | |
}, (error) => { |
This file contains 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
npm install axios cheerio jsonfram-cheerio --save | |
This file contains 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
product : ul.postsList_3n2Ck li | |
|_ name : .content_3Qj0y .title_24w6f | |
|_ description : .content_3Qj0y .subtle_fyrho | |
|_ image : img (attr: src) | |
|_ upvotes : [data-test=vote-button] .buttonContainer_1ROJn | |
|_ comments : [data-test=vote-button] + a .buttonContainer_1ROJn |
This file contains 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
product | |
|_ name | |
|_ description | |
|_ image | |
|_ upvotes | |
|_ comments |
This file contains 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
let cheerio = require('cheerio'); | |
let jsonframe = require('jsonframe-cheerio'); | |
request('https://www.growthhacking.fr', function (error, response, html) { | |
if (!error && response.statusCode == 200) { | |
let $ = cheerio.load('https://www.growthhacking.fr'); | |
jsonframe($); // initializes the plugin | |
var frame = { | |
"post": { // setting the parent item as "companies" |
This file contains 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
// Here is the output data: | |
// { | |
// "companies": [ | |
// { | |
// "name": "Tessera", | |
// "description": "Proud of our wide range of product we developped many project in the past 4 years. You can find the company in 14 different countries in the world. Blablabla.", | |
// "url": "/comp/tessera", | |
// "contact": { | |
// "telephone": "841467168", | |
// "employee": { |
This file contains 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
// Here is the output data: | |
// [ | |
// { | |
// "name": " Tessera ", | |
// "description": " Proud of our wide range of product\n\t\t\t\twe developped many project in the past 4 years. You can find the company \n\t\t\t\tin 14 different countries ", | |
// "contact": { | |
// "telephone": " Phone: (841) 467-168 ", | |
// "employee": { | |
// "name": " Mike Layn ", | |
// "jobTitle": " Marketing Assistant", |
This file contains 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
let cheerio = require('cheerio'); | |
let jsonframe = require('jsonframe-cheerio'); | |
let $ = cheerio.load('our html page url here'); | |
jsonframe($); // initializes the plugin | |
var frame = { | |
"companies": { // setting the parent item as "companies" | |
"selector": ".item", // defines the elements to search for | |
"data": [{ // "data": [{}] defines a list of items |