Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:43:41+00:00 2026-06-18T10:43:41+00:00

I am trying to build a simple webscraper using Request and Cheerio . The

  • 0

I am trying to build a simple webscraper using Request and Cheerio.

The goal right now is to scrape the destination page (in this case http://bukk.it), grab the text from the target selectors on the page, and push it to an array that I can use in other functions.

I understand that request() is executing asynchronously, but do not know how to the scraped data visible outside the function.

example.js

// dependencies
var request = require('request')
, cheerio = require('cheerio');

// variables
var url = 'http://bukk.it/'; // url to scrape
var bukkits = []; // hold our scraped data

request(url, function(err, resp, body){

  if (err) {
    return
  }

  $ = cheerio.load(body);
  // for each of our targets (within the request body)...
  $('td a').each(function(){
    content = $(this).text();
    // I would love to populate the bukkits array for use later...
    bukkits.push(content);
  })
  console.log(bukkits.length); // everything is working inside request
});

console.log(bukkits.length); // nothing, because request is asynchronous?

// that's cool but... how do I actually get the data from the request into bukkits[] ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:43:43+00:00Added an answer on June 18, 2026 at 10:43 am

    Essentially, your entire program must now take place inside the callback. No code after that callback will ever have access to data that was retrieved asynchronously and passed to the callback.

    This isn’t as bad as it sounds. You can use named functions, like so:

    request(url, onRequestDone);
    
    function onRequestDone(err, resp, body) {
      var bukkits = []; // not global, make it local
    
      // as above
    
      doMoreWork(bukkits);
    }
    
    function doMoreWork(bukkits) {
      // stuff after the parsing goes here.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to build simple php crawler for this purpose i am getting
I'm trying to build a simple html page which include some text paragraph, during
I'm trying to build a simple ember application (filebrowser) using an AMD approach (yes
I'm trying to build a simple Android application using NDK. Here are the contents
I'm trying to build a simple Silverlight 3 MediaPlayer using the MediaElement tag: <Border
I'm trying to build a simple scheduler using Quartz.NET, but when I try to
I'm trying to build a simple HTTP Server using Java, using java.net.ServerSocket = new
I'm trying to build a simple site but I'm just blocking on this weird
I am trying to build a simple LAN chat in c# using WPF as
We are trying to build simple transacted jms-to-jms router using Mule ESB and JBoss

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.