ericbae
ericbae

Reputation: 9644

Nodejs "request" returns different content compared to accessing via browser

I'm using NodeJS "request" module to access this particular page

http://www.actapress.com/PaperInfo.aspx?PaperID=28602

via

r = request(i, (err, resp, body) ->
  if err
    console.log err
  else
    console.log body
)

The content of "body" is different compared to when I actually access the URL via the browser. Are there some extra settings that I need to configure for request module?

Upvotes: 0

Views: 80

Answers (2)

Andrey Sidorov
Andrey Sidorov

Reputation: 25466

try to set User-Agent header:

request({
  uri: 'http://www.actapress.com/PaperInfo.aspx?PaperID=28602',
  headers: {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36'
  }
}, function(err, res, body) {
  console.log(body);
});

Upvotes: 1

unlimited
unlimited

Reputation: 471

You can simply use JSON.parse.

body = JSON.parse(body);

Upvotes: 0

Related Questions