Web Scraping with Node.js

Activity 1: Modify the sample code

In this activity, you will modify the sample code


Modifying the Code

Let's modify the sample code so that it pulls out the H3 tags rather than the H2 tags.

Duplicate the Code

Make a copy of scrape1-simple.js, calling it scrape1a-simple.js.

Modify the Code

Locate the section that selects the H2 tags:

    // Search for the elements we want
    selection = $('h2')

Change the code to select the H3 tags instead.

Run the Modified Code

Run the code from the Terminal session in Visual Studio Code:

node scrape1a-simple.js 

You should see data.csv change as follows:

country
Tirana
Yerevan
Vienna
Baku
Minsk
Brussels
Sarajevo
Sofia

Table of Contents

  1. Scrape data from a web page with Cheerio
  2. Activity 1: Modify the sample code
  3. Cheerio Selectors
  4. Activity 2: Trying out Cheerio Selectors
  5. Activity 3: Trying out some Tables
  6. Activity 4: Reading attributes
  7. Activity 5: Books to Scrape
  8. Clicking and Autoscrolling
  9. Links to Scrape Samples