Reputation: 545
I am using a Javascript step on Zapier to scrape html from a URL with the following:
fetch('http://printatestpage.com') //example url
.then(function(res) {
return res.text();
})
.then(function(body) {
var output = {id: 1234, rawHTML: body};
callback(null, output);
})
.catch(callback);
This works great, however I do not need the full HTML body response.
Is it possible to only output a specific div? For instance in the above code say I only wanted the response to output html from class PrintButtons
?
Upvotes: 1
Views: 474
Reputation: 2944
You can parse the rawHTML and use jQuery-like DOM manipulation using cheerio
https://www.npmjs.com/package/cheerio
const cheerio = require('cheerio')
const $ = cheerio.load(rawHTML)
const elementHTMLString = $('.PrintButtons').html()
Upvotes: 1
Reputation: 4866
Unless that host provides some rest API or another service that allows you to directly ask for a specific div, you will have to get the full html and then get the div by id or class name in plain Javascript (or in JQuery or another library).
In case you have the HTML as string, you might need a DOM Parser
Upvotes: 1