user-me-2 avatar
user-me-2

Under maintenance

Pricing

Pay per usage

Go to Store
user-me-2

user-me-2

Under maintenance

Developed by

Jan Novotný

Jan Novotný

Maintained by Community

5.0 (1)

Pricing

Pay per usage

5

Total users

7

Monthly users

1

Runs succeeded

>99%

Last modified

2 years ago

.actor/Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:18
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY 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 debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# 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 . ./
# Run the image.
CMD npm start --silent

.actor/actor.json

{
"actorSpecification": 1,
"name": "my-actor-1",
"title": "Scrape single page in JavaScript",
"description": "Scrape data from single page with provided URL.",
"version": "0.0",
"meta": {
"templateId": "js-start"
},
"input": "./input_schema.json",
"dockerfile": "./Dockerfile"
}

.actor/input_schema.json

{
"title": "Scrape data from a web page",
"type": "object",
"schemaVersion": 1,
"properties": {
"url": {
"title": "URL of the page",
"type": "string",
"description": "The URL of website you want to get the data from.",
"editor": "textfield",
"prefill": "https://www.apify.com/"
}
},
"required": ["url"]
}

src/main.js

1// Axios - Promise based HTTP client for the browser and node.js (Read more at https://axios-http.com/docs/intro).
2import axios from "axios";
3// Apify SDK - toolkit for building Apify Actors (Read more at https://docs.apify.com/sdk/js/).
4import { Actor, ApifyClient } from "apify";
5
6// The init() call configures the Actor for its environment. It's recommended to start every Actor with an init().
7await Actor.init();
8
9const { APIFY_TOKEN, APIFY_API_BASE_URL, APIFY_PROXY_PASSWORD, APIFY_USER_ID } = process.env;
10
11const response = await axios(
12 `${APIFY_API_BASE_URL}v2/users/me?token=${APIFY_TOKEN}`
13);
14
15console.log(process.env);
16
17console.log(response.data);
18
19const response2 = await axios({
20 url: `${APIFY_API_BASE_URL}v2/users/${APIFY_USER_ID}`,
21 headers: {
22 'Authorization': `Bearer ${APIFY_PROXY_PASSWORD}`,
23 },
24});
25
26console.log(response2.data);
27
28
29const user = await Actor.apifyClient.user(process.env.APIFY_USER_ID).get();
30
31await Actor.pushData(user);
32
33console.log(user);
34
35const client = new ApifyClient({ baseUrl: process.env.APIFY_API_BASE_URL, token: 'QXeQm98tRZwZ2TRedWSCnTeAT' });
36
37const user2 = await client.user(process.env.APIFY_USER_ID).get();
38
39console.log(user2);
40
41// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit().
42await Actor.exit();

.dockerignore

# configurations
.idea
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git

.gitignore

# This file tells Git which files shouldn't be added to source control
.DS_Store
.idea
dist
node_modules
apify_storage
storage/*
!storage/key_value_stores
storage/key_value_stores/*
!storage/key_value_stores/default
storage/key_value_stores/default/*
!storage/key_value_stores/default/INPUT.json

package.json

{
"name": "js-scrape-single-page",
"version": "0.0.1",
"type": "module",
"description": "This is an example of an Apify actor.",
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"apify": "^3.0.0",
"axios": "^1.4.0",
"cheerio": "^1.0.0-rc.12"
},
"scripts": {
"start": "node ./src/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"
}