Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no result #2

Open
TokyFy opened this issue Apr 11, 2023 · 1 comment
Open

There is no result #2

TokyFy opened this issue Apr 11, 2023 · 1 comment

Comments

@TokyFy
Copy link
Owner

TokyFy commented Apr 11, 2023

I thinks the website layouts changed , we need to update the scrape selectors !!

@raharinjatovo
Copy link

Hello guys may this help you ;) pure js dont know more about typescript

const axios = require('axios');
const cheerio = require('cheerio');

// Function to scrape the content from a given URL

async function getLyricsByUrl(url){
const page = await axios.get(url);
const $ = cheerio.load(page.data);

// Remove all the Div inside the lyric box

$(".col-md-8 div").remove();
$(".col-md-8 h2").remove();
$(".col-md-8 h5").remove();

return $(".col-md-8").text().trim()

}
async function scrapeContent(url) {
try {
// Make an HTTP GET request to the URL
const response = await axios.get(url);

// Load the HTML content using cheerio
const $ = cheerio.load(response.data);
let data=[];
// Use cheerio selectors to extract the desired content
$(".border.p-2 a").each((_i, el) => {
    const text = $(el).text();
    const link = $(el).attr().href;
    data.push({ text, link });
   
  });
  
  let extractedData = [];

  const chunkSize = 3;
  
  for (let i = 0; i < data.length; i += chunkSize) {
    const chunk = data.slice(i, i + chunkSize);
  
    if (chunk.length === chunkSize) {
      extractedData.push({
        title: chunk[0].text,
        artist: chunk[1].text,
        lyricsLink: chunk[0].link,
      });
    }
  }
  
  //console.log(extractedData);
  extractedData.map(e=>console.log(e))
  
  //console.log(extractedData);

// console.log(data)
const title = $('title').text();

// Return the scraped content as an object
return {
  'extractedData':'da'
};

} catch (error) {
// Handle any errors that occur during the scraping process
throw new Error('Scraping failed:', error);
}
}

// URL of the page you want to scrape
const url = 'https://tononkira.serasera.org/tononkira?lohateny=tiako';

// Scrape the content and log the result
scrapeContent(url)
.then(data => {
console.log('Scraped Data:', data);
})
.catch(error => {
console.error('Error:', error);
});

getLyricsByUrl('https://tononkira.serasera.org/hira/farakely/tiako-izy')
.then(data => {
console.log('Scraped Data:', data);
})
.catch(error => {
console.error('Error:', error);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants