Trying to Scrape an Array

node , cheerio , javascript United States
  • 9 months ago

    I'm trying to scrape the following:

         <tr>
            <td style="font-family:eurof;font-size:14px;padding-top:0px;padding-bottom:5px;"><a style="font-family:eurof;font-size:14px;" href="jewelry">JEWELRY</a>  >  <a style="font-family:eurof;font-size:14px;" href="jewelry/anklet">ANKLET</a>  >  <a style="font-family:eurof;font-size:14px;" href="jewelry/anklet/fashion">FASHION</a>  >  <a style="font-family:eurof;font-size:14px;" href="jewelry/anklet/fashion/"></a>
        	</td>
          </tr>
    

    I use:

    var categories = [];
    const cheerio = require("cheerio");
    const $ = await cheerio.load(content);
    categories.push($('a[style="font-family:eurof;font-size:14px;"]').text());
    
    console.log(categories);
    

    The results of my console.log are:

    [ 'JEWELRYANKLETFASHION' ]

    I want to get

    [ 'JEWELRY','ANKLET','FASHION' ]

  • 9 months ago

    The answer was posted here: https://www.freecodecamp.org/forum/t/trying-to-scrape-an-array/391613/2

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens