Search code examples
pythonnode.jsnode-request

requesting nasdaq.com in python and nodejs


I have encountered the following problem with a get request for nasdaq.com.

I would like to scrape some data with nodejs, but even after hours of trying varous configs all im getting is a 'ECONNRESET'. With python on the other hand, it works like a charm. For now, I have written a workaround fetching the data from node with python-shell and python.

const request = require('request')

const options = {
    url: 'https://www.nasdaq.com/',
    headers: {
        'Connection': 'keep-alive',
        'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11',
        'Accept-Encoding': '',
        'Allow': '/'
    },
}

request(options, (err, res, body) => {
    console.log(err)
    console.log(res.statusCode)
})

results in

{ Error: read ECONNRESET
    at TLSWrap.onread (net.js:660:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

and

from requests import get, Response

res: Response = get('https://www.nasdaq.com/')

print(res.status_code)

results in

200

This occurs only when requesting nasdaq.com. For all other websites the node get works as expected.

What am I doing wrong with the node request?


Solution

  • Use superagent module. It works for me.

    const request = require('superagent')
    
    request.get('www.nasdaq.com', (err, res, body) => {
       console.log(err)
       console.log(res.statusCode)
    });