Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to scrape data from web page with content-encoding: br, doesn't work with options like "JSON=true" or "gzip=true" #347

Open
Sathyajith95 opened this issue Apr 15, 2020 · 0 comments

Comments

@Sathyajith95
Copy link

const request = require("request-promise")
const cheerio = require("cheerio")
const fs = require("fs")
const json2csv = require("json2csv").Parser;

const coronaURL = "https://www.worldometers.info/coronavirus/country/india/";

(async() => {
const coronaData = []
const response = await request({
uri: coronaURL,
headers: {
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en-IN;q=0.9,en;q=0.8,kn;q=0.7",
},
gzip: true,
});

let $ = cheerio.load(response)
let totalCases = $('div[class="maincounter-number"] > span[style="color:#aaa"]').text().trim();
//let totalCases = $('div[class="title_wrapper"]> h1').text().trim();

console.log(totalCases);
coronaData.push({
    totalCases
});

console.log(coronaData);
const json2csvParser = new json2csv();
const csv = json2csvParser.parse(coronaData);

fs.writeFileSync("./coronaCount.csv", csv, "utf-8")

}

)();

This is the node.js code.
I'm new to web-scrapping and node.js.
It returns an empty string. Can anyone please help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant