@crawlee/templates 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/README.md +163 -0
- package/index.d.ts +9 -0
- package/index.d.ts.map +1 -0
- package/index.js +35 -0
- package/index.js.map +1 -0
- package/index.mjs +5 -0
- package/manifest.json +28 -0
- package/package.json +56 -0
- package/templates/cheerio-js/Dockerfile +13 -0
- package/templates/cheerio-js/README.md +33 -0
- package/templates/cheerio-js/package.json +16 -0
- package/templates/cheerio-js/src/main.js +22 -0
- package/templates/cheerio-js/src/routes.js +21 -0
- package/templates/cheerio-ts/Dockerfile +27 -0
- package/templates/cheerio-ts/README.md +33 -0
- package/templates/cheerio-ts/package.json +23 -0
- package/templates/cheerio-ts/src/main.ts +28 -0
- package/templates/cheerio-ts/src/routes.ts +21 -0
- package/templates/cheerio-ts/tsconfig.json +13 -0
- package/templates/playwright-js/Dockerfile +13 -0
- package/templates/playwright-js/README.md +32 -0
- package/templates/playwright-js/package.json +17 -0
- package/templates/playwright-js/src/main.js +22 -0
- package/templates/playwright-js/src/routes.js +21 -0
- package/templates/playwright-ts/Dockerfile +27 -0
- package/templates/playwright-ts/README.md +32 -0
- package/templates/playwright-ts/package.json +24 -0
- package/templates/playwright-ts/src/main.ts +27 -0
- package/templates/playwright-ts/src/routes.ts +21 -0
- package/templates/playwright-ts/tsconfig.json +13 -0
- package/templates/puppeteer-js/Dockerfile +13 -0
- package/templates/puppeteer-js/README.md +32 -0
- package/templates/puppeteer-js/package.json +17 -0
- package/templates/puppeteer-js/src/main.js +22 -0
- package/templates/puppeteer-js/src/routes.js +21 -0
- package/templates/puppeteer-ts/Dockerfile +27 -0
- package/templates/puppeteer-ts/README.md +32 -0
- package/templates/puppeteer-ts/package.json +24 -0
- package/templates/puppeteer-ts/src/main.ts +27 -0
- package/templates/puppeteer-ts/src/routes.ts +21 -0
- package/templates/puppeteer-ts/tsconfig.json +13 -0
- package/tsconfig.build.tsbuildinfo +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Crawlee + CheerioCrawler + TypeScript project
|
|
2
|
+
|
|
3
|
+
This template is a production ready boilerplate for developing with `CheerioCrawler`. Use this to bootstrap your projects using the most up-to-date code.
|
|
4
|
+
|
|
5
|
+
If you're looking for examples or want to learn more visit:
|
|
6
|
+
|
|
7
|
+
- [Tutorial](https://sdk.apify.com/docs/guides/getting-started#cheeriocrawler-aka-jquery-crawler)
|
|
8
|
+
- [Documentation](https://sdk.apify.com/docs/api/cheerio-crawler)
|
|
9
|
+
- [Examples](https://sdk.apify.com/docs/examples/cheerio-crawler)
|
|
10
|
+
|
|
11
|
+
## Documentation reference
|
|
12
|
+
|
|
13
|
+
- [Apify SDK](https://sdk.apify.com/)
|
|
14
|
+
- [Apify Actor documentation](https://docs.apify.com/actor)
|
|
15
|
+
- [Apify CLI](https://docs.apify.com/cli)
|
|
16
|
+
|
|
17
|
+
## Writing a README
|
|
18
|
+
|
|
19
|
+
See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
|
|
20
|
+
|
|
21
|
+
### Table of contents
|
|
22
|
+
|
|
23
|
+
If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
|
|
24
|
+
|
|
25
|
+
<!-- toc start -->
|
|
26
|
+
- Introduction
|
|
27
|
+
- Use Cases
|
|
28
|
+
- Case 1
|
|
29
|
+
- Case 2
|
|
30
|
+
- Input
|
|
31
|
+
- Output
|
|
32
|
+
- Miscellaneous
|
|
33
|
+
<!-- toc end -->
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crawlee-cheerio-ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "This is an example of a Crawlee project.",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"crawlee": "next"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@apify/tsconfig": "^0.1.0",
|
|
11
|
+
"ts-node": "^10.8.0",
|
|
12
|
+
"typescript": "^4.7.4"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "npm run start:dev",
|
|
16
|
+
"start:prod": "node dist/main.js",
|
|
17
|
+
"start:dev": "ts-node-esm -T src/main.ts",
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
|
|
20
|
+
},
|
|
21
|
+
"author": "It's not you it's me",
|
|
22
|
+
"license": "ISC"
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// For more information, see https://crawlee.dev/
|
|
2
|
+
import { CheerioCrawler, KeyValueStore, log, ProxyConfiguration } from 'crawlee';
|
|
3
|
+
import { router } from './routes.js';
|
|
4
|
+
|
|
5
|
+
interface InputSchema {
|
|
6
|
+
startUrls: string[];
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { startUrls = [], debug } = await KeyValueStore.getInput<InputSchema>() ?? {};
|
|
11
|
+
|
|
12
|
+
log.setLevel(log.LEVELS.DEBUG);
|
|
13
|
+
if (debug) {
|
|
14
|
+
log.setLevel(log.LEVELS.DEBUG);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const crawler = new CheerioCrawler({
|
|
18
|
+
// proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
|
|
19
|
+
// Be nice to the websites. Remove to unleash full power.
|
|
20
|
+
maxConcurrency: 50,
|
|
21
|
+
requestHandler: router,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await crawler.addRequests(startUrls);
|
|
25
|
+
|
|
26
|
+
log.info('Starting the crawl.');
|
|
27
|
+
await crawler.run();
|
|
28
|
+
log.info('Crawl finished.');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createCheerioRouter, Dataset } from 'crawlee';
|
|
2
|
+
|
|
3
|
+
export const router = createCheerioRouter();
|
|
4
|
+
|
|
5
|
+
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
|
|
6
|
+
log.info(`Handle Start URLs`);
|
|
7
|
+
await enqueueLinks({
|
|
8
|
+
globs: ['https://apify.com/*'],
|
|
9
|
+
label: 'DETAIL',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
router.addHandler('LIST', async ({ log }) => {
|
|
14
|
+
log.info(`Handle pagination`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
router.addHandler('DETAIL', async ({ request, $, log }) => {
|
|
18
|
+
const title = $('title').text();
|
|
19
|
+
log.info(`Handle details: ${title} [${request.loadedUrl}]`);
|
|
20
|
+
await Dataset.pushData({ url: request.loadedUrl });
|
|
21
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
FROM apify/actor-node-playwright-chrome:16
|
|
2
|
+
|
|
3
|
+
COPY . ./
|
|
4
|
+
|
|
5
|
+
# install only prod deps
|
|
6
|
+
RUN npm --quiet set progress=false \
|
|
7
|
+
&& npm install --only=prod --no-optional \
|
|
8
|
+
&& echo "Installed NPM packages:" \
|
|
9
|
+
&& (npm list --only=prod --no-optional --all || true) \
|
|
10
|
+
&& echo "Node.js version:" \
|
|
11
|
+
&& node --version \
|
|
12
|
+
&& echo "NPM version:" \
|
|
13
|
+
&& npm --version
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Crawlee + PlaywrightCrawler + JavaScript project
|
|
2
|
+
|
|
3
|
+
This template is a production ready boilerplate for developing with `PlaywrightCrawler`. Use this to bootstrap your projects using the most up-to-date code.
|
|
4
|
+
|
|
5
|
+
If you're looking for examples or want to learn more visit:
|
|
6
|
+
|
|
7
|
+
- [Documentation](https://sdk.apify.com/docs/api/playwright-crawler)
|
|
8
|
+
- [Examples](https://sdk.apify.com/docs/examples/playwright-crawler)
|
|
9
|
+
|
|
10
|
+
## Documentation reference
|
|
11
|
+
|
|
12
|
+
- [Apify SDK](https://sdk.apify.com/)
|
|
13
|
+
- [Apify Actor documentation](https://docs.apify.com/actor)
|
|
14
|
+
- [Apify CLI](https://docs.apify.com/cli)
|
|
15
|
+
|
|
16
|
+
## Writing a README
|
|
17
|
+
|
|
18
|
+
See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
|
|
19
|
+
|
|
20
|
+
### Table of contents
|
|
21
|
+
|
|
22
|
+
If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
|
|
23
|
+
|
|
24
|
+
<!-- toc start -->
|
|
25
|
+
- Introduction
|
|
26
|
+
- Use Cases
|
|
27
|
+
- Case 1
|
|
28
|
+
- Case 2
|
|
29
|
+
- Input
|
|
30
|
+
- Output
|
|
31
|
+
- Miscellaneous
|
|
32
|
+
<!-- toc end -->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crawlee-playwright-js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "This is an example of a Crawlee project.",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"crawlee": "next",
|
|
8
|
+
"playwright": "*"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node src/main.js",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"author": "It's not you it's me",
|
|
16
|
+
"license": "ISC"
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// For more information, see https://crawlee.dev/
|
|
2
|
+
import { KeyValueStore, PlaywrightCrawler, ProxyConfiguration, log } from 'crawlee';
|
|
3
|
+
import { router } from './routes.js';
|
|
4
|
+
|
|
5
|
+
const { startUrls = [], debug } = await KeyValueStore.getInput() ?? {};
|
|
6
|
+
|
|
7
|
+
if (debug) {
|
|
8
|
+
log.setLevel(log.LEVELS.DEBUG);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const crawler = new PlaywrightCrawler({
|
|
12
|
+
// proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
|
|
13
|
+
// Be nice to the websites. Remove to unleash full power.
|
|
14
|
+
maxConcurrency: 50,
|
|
15
|
+
requestHandler: router,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await crawler.addRequests(startUrls);
|
|
19
|
+
|
|
20
|
+
log.info('Starting the crawl.');
|
|
21
|
+
await crawler.run();
|
|
22
|
+
log.info('Crawl finished.');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dataset, createPlaywrightRouter } from 'crawlee';
|
|
2
|
+
|
|
3
|
+
export const router = createPlaywrightRouter();
|
|
4
|
+
|
|
5
|
+
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
|
|
6
|
+
log.info(`Handle Start URLs`);
|
|
7
|
+
await enqueueLinks({
|
|
8
|
+
globs: ['https://apify.com/*'],
|
|
9
|
+
label: 'DETAIL',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
router.addHandler('handleList', async ({ log }) => {
|
|
14
|
+
log.info(`Handle pagination`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
router.addHandler('handleDetail', async ({ request, page, log }) => {
|
|
18
|
+
const title = await page.title();
|
|
19
|
+
log.info(`Handle details: ${title} [${request.loadedUrl}]`);
|
|
20
|
+
await Dataset.pushData({ url: request.loadedUrl });
|
|
21
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# using multistage build, as we need dev deps to build the TS source code
|
|
2
|
+
FROM apify/actor-node:16 AS builder
|
|
3
|
+
|
|
4
|
+
# copy all files, install all dependencies (including dev deps) and build the project
|
|
5
|
+
COPY . ./
|
|
6
|
+
RUN npm install --include=dev \
|
|
7
|
+
&& npm run build
|
|
8
|
+
|
|
9
|
+
# create final image
|
|
10
|
+
FROM apify/actor-node-playwright-chrome:16
|
|
11
|
+
# copy only necessary files
|
|
12
|
+
COPY --from=builder /usr/src/app/package.json ./
|
|
13
|
+
COPY --from=builder /usr/src/app/README.md ./
|
|
14
|
+
COPY --from=builder /usr/src/app/dist ./dist
|
|
15
|
+
|
|
16
|
+
# install only prod deps
|
|
17
|
+
RUN npm --quiet set progress=false \
|
|
18
|
+
&& npm install --only=prod --no-optional \
|
|
19
|
+
&& echo "Installed NPM packages:" \
|
|
20
|
+
&& (npm list --only=prod --no-optional --all || true) \
|
|
21
|
+
&& echo "Node.js version:" \
|
|
22
|
+
&& node --version \
|
|
23
|
+
&& echo "NPM version:" \
|
|
24
|
+
&& npm --version
|
|
25
|
+
|
|
26
|
+
# run compiled code
|
|
27
|
+
CMD npm run start:prod
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Crawlee + PlaywrightCrawler + TypeScript project
|
|
2
|
+
|
|
3
|
+
This template is a production ready boilerplate for developing with `PlaywrightCrawler`. Use this to bootstrap your projects using the most up-to-date code.
|
|
4
|
+
|
|
5
|
+
If you're looking for examples or want to learn more visit:
|
|
6
|
+
|
|
7
|
+
- [Documentation](https://sdk.apify.com/docs/api/playwright-crawler)
|
|
8
|
+
- [Examples](https://sdk.apify.com/docs/examples/playwright-crawler)
|
|
9
|
+
|
|
10
|
+
## Documentation reference
|
|
11
|
+
|
|
12
|
+
- [Apify SDK](https://sdk.apify.com/)
|
|
13
|
+
- [Apify Actor documentation](https://docs.apify.com/actor)
|
|
14
|
+
- [Apify CLI](https://docs.apify.com/cli)
|
|
15
|
+
|
|
16
|
+
## Writing a README
|
|
17
|
+
|
|
18
|
+
See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
|
|
19
|
+
|
|
20
|
+
### Table of contents
|
|
21
|
+
|
|
22
|
+
If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
|
|
23
|
+
|
|
24
|
+
<!-- toc start -->
|
|
25
|
+
- Introduction
|
|
26
|
+
- Use Cases
|
|
27
|
+
- Case 1
|
|
28
|
+
- Case 2
|
|
29
|
+
- Input
|
|
30
|
+
- Output
|
|
31
|
+
- Miscellaneous
|
|
32
|
+
<!-- toc end -->
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crawlee-playwright-ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "This is an example of a Crawlee project.",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"crawlee": "next",
|
|
8
|
+
"playwright": "*"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@apify/tsconfig": "^0.1.0",
|
|
12
|
+
"ts-node": "^10.8.0",
|
|
13
|
+
"typescript": "^4.7.4"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"start": "npm run start:dev",
|
|
17
|
+
"start:prod": "node dist/main.js",
|
|
18
|
+
"start:dev": "ts-node-esm -T src/main.ts",
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"author": "It's not you it's me",
|
|
23
|
+
"license": "ISC"
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// For more information, see https://crawlee.dev/
|
|
2
|
+
import { KeyValueStore, PlaywrightCrawler, ProxyConfiguration, log } from 'crawlee';
|
|
3
|
+
import { router } from './routes.js';
|
|
4
|
+
|
|
5
|
+
interface InputSchema {
|
|
6
|
+
startUrls: string[];
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { startUrls = [], debug } = await KeyValueStore.getInput<InputSchema>() ?? {};
|
|
11
|
+
|
|
12
|
+
if (debug) {
|
|
13
|
+
log.setLevel(log.LEVELS.DEBUG);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const crawler = new PlaywrightCrawler({
|
|
17
|
+
// proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
|
|
18
|
+
// Be nice to the websites. Remove to unleash full power.
|
|
19
|
+
maxConcurrency: 50,
|
|
20
|
+
requestHandler: router,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await crawler.addRequests(startUrls);
|
|
24
|
+
|
|
25
|
+
log.info('Starting the crawl.');
|
|
26
|
+
await crawler.run();
|
|
27
|
+
log.info('Crawl finished.');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dataset, createPlaywrightRouter } from 'crawlee';
|
|
2
|
+
|
|
3
|
+
export const router = createPlaywrightRouter();
|
|
4
|
+
|
|
5
|
+
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
|
|
6
|
+
log.info(`Handle Start URLs`);
|
|
7
|
+
await enqueueLinks({
|
|
8
|
+
globs: ['https://apify.com/*'],
|
|
9
|
+
label: 'DETAIL',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
router.addHandler('handleList', async ({ log }) => {
|
|
14
|
+
log.info(`Handle pagination`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
router.addHandler('handleDetail', async ({ request, page, log }) => {
|
|
18
|
+
const title = await page.title();
|
|
19
|
+
log.info(`Handle details: ${title} [${request.loadedUrl}]`);
|
|
20
|
+
await Dataset.pushData({ url: request.loadedUrl });
|
|
21
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
FROM apify/actor-node-puppeteer-chrome:16
|
|
2
|
+
|
|
3
|
+
COPY . ./
|
|
4
|
+
|
|
5
|
+
# install only prod deps
|
|
6
|
+
RUN npm --quiet set progress=false \
|
|
7
|
+
&& npm install --only=prod --no-optional \
|
|
8
|
+
&& echo "Installed NPM packages:" \
|
|
9
|
+
&& (npm list --only=prod --no-optional --all || true) \
|
|
10
|
+
&& echo "Node.js version:" \
|
|
11
|
+
&& node --version \
|
|
12
|
+
&& echo "NPM version:" \
|
|
13
|
+
&& npm --version
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Crawlee + PuppeteerCrawler + JavaScript project
|
|
2
|
+
|
|
3
|
+
This template is a production ready boilerplate for developing with `PuppeteerCrawler`. Use this to bootstrap your projects using the most up-to-date code.
|
|
4
|
+
|
|
5
|
+
If you're looking for examples or want to learn more visit:
|
|
6
|
+
|
|
7
|
+
- [Documentation](https://sdk.apify.com/docs/api/puppeteer-crawler)
|
|
8
|
+
- [Examples](https://sdk.apify.com/docs/examples/puppeteer-crawler)
|
|
9
|
+
|
|
10
|
+
## Documentation reference
|
|
11
|
+
|
|
12
|
+
- [Apify SDK](https://sdk.apify.com/)
|
|
13
|
+
- [Apify Actor documentation](https://docs.apify.com/actor)
|
|
14
|
+
- [Apify CLI](https://docs.apify.com/cli)
|
|
15
|
+
|
|
16
|
+
## Writing a README
|
|
17
|
+
|
|
18
|
+
See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
|
|
19
|
+
|
|
20
|
+
### Table of contents
|
|
21
|
+
|
|
22
|
+
If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
|
|
23
|
+
|
|
24
|
+
<!-- toc start -->
|
|
25
|
+
- Introduction
|
|
26
|
+
- Use Cases
|
|
27
|
+
- Case 1
|
|
28
|
+
- Case 2
|
|
29
|
+
- Input
|
|
30
|
+
- Output
|
|
31
|
+
- Miscellaneous
|
|
32
|
+
<!-- toc end -->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crawlee-puppeteer-js",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "This is an example of a Crawlee project.",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"crawlee": "next",
|
|
8
|
+
"puppeteer": "*"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "node src/main.js",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"author": "It's not you it's me",
|
|
16
|
+
"license": "ISC"
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// For more information, see https://crawlee.dev/
|
|
2
|
+
import { KeyValueStore, PuppeteerCrawler, ProxyConfiguration, log } from 'crawlee';
|
|
3
|
+
import { router } from './routes.js';
|
|
4
|
+
|
|
5
|
+
const { startUrls = [], debug } = await KeyValueStore.getInput() ?? {};
|
|
6
|
+
|
|
7
|
+
if (debug) {
|
|
8
|
+
log.setLevel(log.LEVELS.DEBUG);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const crawler = new PuppeteerCrawler({
|
|
12
|
+
// proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
|
|
13
|
+
// Be nice to the websites. Remove to unleash full power.
|
|
14
|
+
maxConcurrency: 50,
|
|
15
|
+
requestHandler: router,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await crawler.addRequests(startUrls);
|
|
19
|
+
|
|
20
|
+
log.info('Starting the crawl.');
|
|
21
|
+
await crawler.run();
|
|
22
|
+
log.info('Crawl finished.');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dataset, createPuppeteerRouter } from 'crawlee';
|
|
2
|
+
|
|
3
|
+
export const router = createPuppeteerRouter();
|
|
4
|
+
|
|
5
|
+
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
|
|
6
|
+
log.info(`Handle Start URLs`);
|
|
7
|
+
await enqueueLinks({
|
|
8
|
+
globs: ['https://apify.com/*'],
|
|
9
|
+
label: 'DETAIL',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
router.addHandler('handleList', async ({ log }) => {
|
|
14
|
+
log.info(`Handle pagination`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
router.addHandler('handleDetail', async ({ request, page, log }) => {
|
|
18
|
+
const title = await page.title();
|
|
19
|
+
log.info(`Handle details: ${title} [${request.loadedUrl}]`);
|
|
20
|
+
await Dataset.pushData({ url: request.loadedUrl });
|
|
21
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# using multistage build, as we need dev deps to build the TS source code
|
|
2
|
+
FROM apify/actor-node:16 AS builder
|
|
3
|
+
|
|
4
|
+
# copy all files, install all dependencies (including dev deps) and build the project
|
|
5
|
+
COPY . ./
|
|
6
|
+
RUN npm install --include=dev \
|
|
7
|
+
&& npm run build
|
|
8
|
+
|
|
9
|
+
# create final image
|
|
10
|
+
FROM apify/actor-node-puppeteer-chrome:16
|
|
11
|
+
# copy only necessary files
|
|
12
|
+
COPY --from=builder /usr/src/app/package.json ./
|
|
13
|
+
COPY --from=builder /usr/src/app/README.md ./
|
|
14
|
+
COPY --from=builder /usr/src/app/dist ./dist
|
|
15
|
+
|
|
16
|
+
# install only prod deps
|
|
17
|
+
RUN npm --quiet set progress=false \
|
|
18
|
+
&& npm install --only=prod --no-optional \
|
|
19
|
+
&& echo "Installed NPM packages:" \
|
|
20
|
+
&& (npm list --only=prod --no-optional --all || true) \
|
|
21
|
+
&& echo "Node.js version:" \
|
|
22
|
+
&& node --version \
|
|
23
|
+
&& echo "NPM version:" \
|
|
24
|
+
&& npm --version
|
|
25
|
+
|
|
26
|
+
# run compiled code
|
|
27
|
+
CMD npm run start:prod
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Crawlee + PuppeteerCrawler + TypeScript project
|
|
2
|
+
|
|
3
|
+
This template is a production ready boilerplate for developing with `PuppeteerCrawler`. Use this to bootstrap your projects using the most up-to-date code.
|
|
4
|
+
|
|
5
|
+
If you're looking for examples or want to learn more visit:
|
|
6
|
+
|
|
7
|
+
- [Documentation](https://sdk.apify.com/docs/api/puppeteer-crawler)
|
|
8
|
+
- [Examples](https://sdk.apify.com/docs/examples/puppeteer-crawler)
|
|
9
|
+
|
|
10
|
+
## Documentation reference
|
|
11
|
+
|
|
12
|
+
- [Apify SDK](https://sdk.apify.com/)
|
|
13
|
+
- [Apify Actor documentation](https://docs.apify.com/actor)
|
|
14
|
+
- [Apify CLI](https://docs.apify.com/cli)
|
|
15
|
+
|
|
16
|
+
## Writing a README
|
|
17
|
+
|
|
18
|
+
See our tutorial on [writing READMEs for your actors](https://help.apify.com/en/articles/2912548-how-to-write-great-readme-for-your-actors) if you need more inspiration.
|
|
19
|
+
|
|
20
|
+
### Table of contents
|
|
21
|
+
|
|
22
|
+
If your README requires a table of contents, use the template below and make sure to keep the `<!-- toc start -->` and `<!-- toc end -->` markers.
|
|
23
|
+
|
|
24
|
+
<!-- toc start -->
|
|
25
|
+
- Introduction
|
|
26
|
+
- Use Cases
|
|
27
|
+
- Case 1
|
|
28
|
+
- Case 2
|
|
29
|
+
- Input
|
|
30
|
+
- Output
|
|
31
|
+
- Miscellaneous
|
|
32
|
+
<!-- toc end -->
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crawlee-puppeteer-ts",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "This is an example of a Crawlee project.",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"crawlee": "next",
|
|
8
|
+
"puppeteer": "*"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@apify/tsconfig": "^0.1.0",
|
|
12
|
+
"ts-node": "^10.8.0",
|
|
13
|
+
"typescript": "^4.7.4"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"start": "npm run start:dev",
|
|
17
|
+
"start:prod": "node dist/main.js",
|
|
18
|
+
"start:dev": "ts-node-esm -T src/main.ts",
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"author": "It's not you it's me",
|
|
23
|
+
"license": "ISC"
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// For more information, see https://crawlee.dev/
|
|
2
|
+
import { KeyValueStore, PuppeteerCrawler, ProxyConfiguration, log } from 'crawlee';
|
|
3
|
+
import { router } from './routes.js';
|
|
4
|
+
|
|
5
|
+
interface InputSchema {
|
|
6
|
+
startUrls: string[];
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { startUrls = [], debug } = await KeyValueStore.getInput<InputSchema>() ?? {};
|
|
11
|
+
|
|
12
|
+
if (debug) {
|
|
13
|
+
log.setLevel(log.LEVELS.DEBUG);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const crawler = new PuppeteerCrawler({
|
|
17
|
+
// proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
|
|
18
|
+
// Be nice to the websites. Remove to unleash full power.
|
|
19
|
+
maxConcurrency: 50,
|
|
20
|
+
requestHandler: router,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
await crawler.addRequests(startUrls);
|
|
24
|
+
|
|
25
|
+
log.info('Starting the crawl.');
|
|
26
|
+
await crawler.run();
|
|
27
|
+
log.info('Crawl finished.');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Dataset, createPuppeteerRouter } from 'crawlee';
|
|
2
|
+
|
|
3
|
+
export const router = createPuppeteerRouter();
|
|
4
|
+
|
|
5
|
+
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
|
|
6
|
+
log.info(`Handle Start URLs`);
|
|
7
|
+
await enqueueLinks({
|
|
8
|
+
globs: ['https://apify.com/*'],
|
|
9
|
+
label: 'DETAIL',
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
router.addHandler('handleList', async ({ log }) => {
|
|
14
|
+
log.info(`Handle pagination`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
router.addHandler('handleDetail', async ({ request, page, log }) => {
|
|
18
|
+
const title = await page.title();
|
|
19
|
+
log.info(`Handle details: ${title} [${request.loadedUrl}]`);
|
|
20
|
+
await Dataset.pushData({ url: request.loadedUrl });
|
|
21
|
+
});
|