@crawlee/templates 3.0.1 → 3.0.2-beta.2

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.
Files changed (36) hide show
  1. package/manifest.json +28 -0
  2. package/package.json +1 -1
  3. package/templates/cheerio-js/Dockerfile +13 -0
  4. package/templates/cheerio-js/README.md +33 -0
  5. package/templates/cheerio-js/package.json +16 -0
  6. package/templates/cheerio-js/src/main.js +22 -0
  7. package/templates/cheerio-js/src/routes.js +21 -0
  8. package/templates/cheerio-ts/Dockerfile +27 -0
  9. package/templates/cheerio-ts/README.md +33 -0
  10. package/templates/cheerio-ts/package.json +23 -0
  11. package/templates/cheerio-ts/src/main.ts +27 -0
  12. package/templates/cheerio-ts/src/routes.ts +21 -0
  13. package/templates/cheerio-ts/tsconfig.json +13 -0
  14. package/templates/playwright-js/Dockerfile +13 -0
  15. package/templates/playwright-js/README.md +32 -0
  16. package/templates/playwright-js/package.json +17 -0
  17. package/templates/playwright-js/src/main.js +22 -0
  18. package/templates/playwright-js/src/routes.js +21 -0
  19. package/templates/playwright-ts/Dockerfile +27 -0
  20. package/templates/playwright-ts/README.md +32 -0
  21. package/templates/playwright-ts/package.json +24 -0
  22. package/templates/playwright-ts/src/main.ts +27 -0
  23. package/templates/playwright-ts/src/routes.ts +21 -0
  24. package/templates/playwright-ts/tsconfig.json +13 -0
  25. package/templates/puppeteer-js/Dockerfile +13 -0
  26. package/templates/puppeteer-js/README.md +32 -0
  27. package/templates/puppeteer-js/package.json +17 -0
  28. package/templates/puppeteer-js/src/main.js +22 -0
  29. package/templates/puppeteer-js/src/routes.js +21 -0
  30. package/templates/puppeteer-ts/Dockerfile +27 -0
  31. package/templates/puppeteer-ts/README.md +32 -0
  32. package/templates/puppeteer-ts/package.json +24 -0
  33. package/templates/puppeteer-ts/src/main.ts +27 -0
  34. package/templates/puppeteer-ts/src/routes.ts +21 -0
  35. package/templates/puppeteer-ts/tsconfig.json +13 -0
  36. package/tsconfig.build.tsbuildinfo +1 -1
@@ -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": "^3.0.0",
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 = ['https://apify.com'], 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
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@apify/tsconfig",
3
+ "compilerOptions": {
4
+ "module": "ES2022",
5
+ "target": "ES2022",
6
+ "outDir": "dist",
7
+ "noUnusedLocals": false,
8
+ "lib": ["DOM"]
9
+ },
10
+ "include": [
11
+ "./src/**/*"
12
+ ]
13
+ }