Hi.
Could you please help me with this code?
I am making an HTTP request that returns data, HTML content.
Next, I am doing some check.
If it passes, I need to extract an IMG element from that HTML (data variable), return the SRC property of that element and pass it to the next step.
Obviously, the const $ = cheerio.load(data)
generates an error, since $ is already declared above.
How can I achieve the desired functionality? Thank you.
// To use any npm package on Pipedream, just import it
import axios from "axios";
import cheerio from 'cheerio';
export default defineComponent({
async run({ steps, $ }) {
const { data } = await axios({
method: "GET",
url: "https://www.youtube.com/@TwoCatsVideoProduction/streams"
})
if(data.indexOf("upcomingEventData") == -1) {
$.flow.exit("Skipping execution if no upcoming event");
}
// Load the HTML string
const $ = cheerio.load(data);
// Select the element
const thumbnailImg = $('#thumbnail > yt-image > img');
// Get the src attribute of the image
const src = thumbnailImg.attr('src');
return src;
},
})