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 7745673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:04:50+00:00 2026-06-01T10:04:50+00:00

NOOb here. I’ve got a HTTP request that pulls all of the content from

  • 0

NOOb here. I’ve got a HTTP request that pulls all of the content from a specific webpage. However, all I need is a specific string:"Most recent instantaneous value: ". In fact, I actually need to store the value that follows value:. Here is my code:

var http = require("http");

var options = {
 host: 'waterdata.usgs.gov',
 port: 80,
 path: '/ga/nwis/uv?cb_72036=on&cb_00062=on&format=gif_default&period=1&site_no=02334400',
 method: 'POST'
};

var req = http.request(options, function(res) {
 console.log('STATUS: ' + res.statusCode);
 console.log('HEADERS: ' + JSON.stringify(res.headers));
 res.setEncoding('utf8');
 res.on('data', function (chunk) {
 console.log('BODY: ' + chunk);
 });
});

req.on('error', function(e) {
 console.log('problem with request: ' + e.message);
});

// write data to request body
req.write('data\n');
req.write('data\n');
req.end();

I realize I don’t need all the console.log statements, but do I need keep console.log('BODY: ' + chunk); so all of the data downloads?

  • 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-01T10:04:51+00:00Added an answer on June 1, 2026 at 10:04 am

    Never do it the way I’m doing it in this quick’n’dirty example. There are plenty of modules for DOM traversal, HTML/XML parsing, etc… They are a lot safer then a simple regex. But just so you get the general idea:

    var http = require("http");
    
    var options = {
        host: 'waterdata.usgs.gov',
        port: 80,
        path: '/ga/nwis/uv?cb_72036=on&cb_00062=on&format=gif_default&period=1&site_no=02334400',
    };
    
    function extract (body, cb) {
        if(!body) 
            return;
    
        var matches=body.match(/Most recent instantaneous value: ([^ ]+) /);
        if(matches)
            cb(matches[1]);
    }
    
    http.get(options, function(res) {
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            extract(chunk, function(v){ console.log(v); });
        });
    }).on('error', function(e) {
        console.log('problem with request: ' + e.message);
    });
    

    Somehow I also got a different page when sending a POST instead of a GET request. So I changed that bit…

    Regarding your second question: No you don’t need to keep any of the console.log() statements. Just use callbacks and everything is fine! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

noob here and need help from the pros... i am doing a voice record
Noob here. I have a rails app that has users and postings. I need
noob here i got this jquery code that i found on stackoverflow var maxLines
c#/oop noob here. I am creating a datatable from the schema of a sql
Noob question here! I have an array with hashes that looks like this: arr
Python noob here, Currently I'm working with SQLAlchemy, and I have this: from __init__
Javascript noob here (I'm assuming I will need Javascript to solve this). I need
jQuery noob here (don't most posts start like that?) I know I could do
noob here, I'm trying to transfer a file using rsync from windows to linux.
Noob here... :) I'm working on a small and personal project that is already

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.