AI
Have a scraping or integration task? Let our AI solve it.
Describe what data you need or which systems to connect — our AI builds and runs the scraper or integration for you. No coding required.
Free to try · already have an account?
Cheerio Node.Js for fields extraction. Lets try to export product price,title,sku
At previous articles we learned how to create a simple web scraper using NodeJs and axios. https://mydataprovider.com/blog/how-to-create-a-web-scraper-using-nodejs-and-axios/ Axios Node.Js module allows us to load html page source. Now we have to extract required fields from html and we will do that via Cheerio module for NodeJs.
<div class="nv-content-wrap entry-content">
<table width="200px">
<tbody>
<tr>
<td>Sku:
</td>
<td>
<div class="sku">
testSku
</div>
</td>
<td>Price:
</td>
<td>
<div class="price-value">
123
</div>
</td>
<td>
Currency:
</td>
<td>
<div class="price-currency">
USD
</div>
</td>
</tr>
</tbody>
</table>
</div>
here is a code for fields extraction
async function extractData(html)
{
const cheerio = require('cheerio');
const $ = cheerio.load(html);
var sku = $('.sku').first().html().trim();
var title = $('h1').first().html().trim();
var price = $('.price-value').first().html().trim();
var currency = $('.price-currency').first().html().trim();
console.log('sku:' + sku);
console.log('title:' + title);
console.log('price:' + price);
console.log('currency:' + currency);
}
This cheerio code sample from visual studio:
Hope this sample will help you to extract required for you fields from source sites / html pages.