959395053th covid api
Under maintenance
Pricing
Pay per usage
Go to Store
959395053th covid api
Under maintenance
0.0 (0)
Pricing
Pay per usage
1
Total users
4
Monthly users
1
Runs succeeded
0%
Last modified
3 years ago
.gitignore
# This file tells Git which files shouldn't be added to source control
.ideanode_modules
Dockerfile
# First, specify the base Docker image. You can read more about# the available images at https://sdk.apify.com/docs/guides/docker-images# You can also use any other image from Docker Hub.FROM apify/actor-node-puppeteer-chrome:16
# Second, copy just package.json and package-lock.json since it should be# the only file that affects "npm install" in the next step, to speed up the buildCOPY package*.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --only=prod --no-optional \ && echo "Installed NPM packages:" \ && (npm list --only=prod --no-optional --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Optionally, specify how to launch the source code of your actor.# By default, Apify's base Docker images define the CMD instruction# that runs the Node.js source code using the command specified# in the "scripts.start" section of the package.json file.# In short, the instruction looks something like this:## CMD npm start
apify.json
{ "env": { "npm_config_loglevel": "silent" }}
main.js
1// This is the main Node.js source code file of your actor.2// It is referenced from the "scripts" section of the package.json file,3// so that it can be started by running "npm start".4
5// Import Apify SDK. For more information, see https://sdk.apify.com/6const Apify = require('apify');7
8Apify.main(async () => {9 // Get input of the actor (here only for demonstration purposes).10 // If you'd like to have your input checked and have Apify display11 // a user interface for it, add INPUT_SCHEMA.json file to your actor.12 // For more information, see https://docs.apify.com/actors/development/input-schema13 console.log('URL:');14 const input = {url: "https://covid19.who.int/"};15 if (!input || !input.url) throw new Error('Input must be a JSON object with the "url" field!');16
17 console.log('Launching Puppeteer...');18 const browser = await Apify.launchPuppeteer();19
20 console.log(`Opening page ${input.url}...`);21 const page = await browser.newPage();22 await page.goto(input.url);23 await page.waitForXPath(`//*[@id="gatsby-focus-wrapper"]/div/div[4]/div[1]/div/div/div[2]/div[3]/span[1]`, {visible: true});24 const [casesElem] = await page.$x(`//*[@id="gatsby-focus-wrapper"]/div/div[4]/div[1]/div/div/div[2]/div[3]/span[1]`);25 const casesCommas = await page.evaluate(name => name.innerText, casesElem);26 const cases = parseInt(casesCommas.replaceAll(",",""));27
28 await page.waitForXPath(`//*[@id="gatsby-focus-wrapper"]/div/div[4]/div[1]/div/div/div[2]/div[4]/span[1]`, {visible:true});29 const [deathsElem] = await page.$x(`//*[@id="gatsby-focus-wrapper"]/div/div[4]/div[1]/div/div/div[2]/div[4]/span[1]`);30 const deathsCommas = await page.evaluate(name => name.innerText, deathsElem);31 const deaths = parseInt(deathsCommas.replaceAll(",",""));32
33 console.log('Saving output...');34 await Apify.setValue('OUTPUT', {35 cases,36 casesCommas,37 deaths,38 deathsCommas,39 });40
41 console.log('Closing Puppeteer...');42 await browser.close();43
44 console.log('Done.');45});
package.json
{ "name": "example-puppeteer-single-page", "version": "0.0.1", "description": "This is an example of an Apify actor.", "dependencies": { "apify": "^2.0.7", "puppeteer": "*" }, "devDependencies": {}, "scripts": { "start": "node main.js", "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1" }, "author": "It's not you it's me", "license": "ISC"}