0
I need to create a bot that enters the home page of a particular site, take all the link’s of the posts, enter a, capture a div that contains the video and move on to the next link captured on the index.
I’ve already created the part that captures the link, now I need to know how to do the part to access them and capture the div who owns the video
request("https://www.site.com", function(error, response, html)
{
if(!error)
{
var $ = cheerio.load(html)
var resultado = [];
$("div.mozaique > div.thumb-block").each(function(i)
{
var title = $(this).find("div.thumb-under > p > a").eq(0).text();
var link = $(this).find("div.thumb-under > p > a").attr("href");
var img = $(this).find("div.thumb-inside > div.thumb > a > img").attr("data-src");
resultado.push({
id: i,
title: title,
link: link,
img: img
});
});
}
// Escrevendo o arquivo .json com o array
fs.writeFile('resultado.json', JSON.stringify(resultado, null, 4), function(err) {
console.log('JSON escrito com sucesso! O arquivo está na raiz do projeto.')
})
});
If that’s not clear, I basically need:
- Log in
- Capture the posts link and store them
- Enter the first captured link
- Catch a div that contains a link . mp4
- Go to the next link captured and repeat step 4 and 5.
Have you tried creating a function to access the link and capture the video? This way you can make a
for
on the captured links.– Valdeir Psr
That’s exactly what I can’t do!
– Vinicius Cavalheiro