959395053th covid api
Try for free
No credit card required
View all Actors
This Actor may be unreliable while under maintenance. Would you like to try a similar Actor instead?
See alternative Actors959395053th covid api
hreal/my-actor
Try for free
No credit card required
.gitignore
1# This file tells Git which files shouldn't be added to source control
2
3.idea
4node_modules
Dockerfile
1# First, specify the base Docker image. You can read more about
2# the available images at https://sdk.apify.com/docs/guides/docker-images
3# You can also use any other image from Docker Hub.
4FROM apify/actor-node-puppeteer-chrome:16
5
6# Second, copy just package.json and package-lock.json since it should be
7# the only file that affects "npm install" in the next step, to speed up the build
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --only=prod --no-optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --only=prod --no-optional --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version
21
22# Next, copy the remaining files and directories with the source code.
23# Since we do this after NPM install, quick build will be really fast
24# for most source file changes.
25COPY . ./
26
27# Optionally, specify how to launch the source code of your actor.
28# By default, Apify's base Docker images define the CMD instruction
29# that runs the Node.js source code using the command specified
30# in the "scripts.start" section of the package.json file.
31# In short, the instruction looks something like this:
32#
33# CMD npm start
apify.json
1{
2 "env": { "npm_config_loglevel": "silent" }
3}
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 display
11 // 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-schema
13 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
1{
2 "name": "example-puppeteer-single-page",
3 "version": "0.0.1",
4 "description": "This is an example of an Apify actor.",
5 "dependencies": {
6 "apify": "^2.0.7",
7 "puppeteer": "*"
8 },
9 "devDependencies": {},
10 "scripts": {
11 "start": "node main.js",
12 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
13 },
14 "author": "It's not you it's me",
15 "license": "ISC"
16}
Developer
Maintained by Community
Actor Metrics
1 monthly user
-
1 star
0% runs succeeded
Created in Feb 2022
Modified 3 years ago
Categories