Created a new Crawlee + PlaywrightCrawler + TypeScript project.
This commit is contained in:
commit
5adac13cf7
10
.dockerignore
Normal file
10
.dockerignore
Normal file
|
@ -0,0 +1,10 @@
|
|||
# configurations
|
||||
.idea
|
||||
|
||||
# crawlee and apify storage folders
|
||||
apify_storage
|
||||
crawlee_storage
|
||||
storage
|
||||
|
||||
# installed files
|
||||
node_modules
|
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# This file tells Git which files shouldn't be added to source control
|
||||
|
||||
.idea
|
||||
dist
|
||||
node_modules
|
||||
apify_storage
|
||||
crawlee_storage
|
||||
storage
|
51
Dockerfile
Normal file
51
Dockerfile
Normal file
|
@ -0,0 +1,51 @@
|
|||
# Specify the base Docker image. You can read more about
|
||||
# the available images at https://crawlee.dev/docs/guides/docker-images
|
||||
# You can also use any other image from Docker Hub.
|
||||
FROM apify/actor-node-playwright-chrome:20 AS builder
|
||||
|
||||
# Copy just package.json and package-lock.json
|
||||
# to speed up the build using Docker layer cache.
|
||||
COPY --chown=myuser package*.json ./
|
||||
|
||||
# Install all dependencies. Don't audit to speed up the installation.
|
||||
RUN npm install --include=dev --audit=false
|
||||
|
||||
# Next, copy the source files using the user set
|
||||
# in the base image.
|
||||
COPY --chown=myuser . ./
|
||||
|
||||
# Install all dependencies and build the project.
|
||||
# Don't audit to speed up the installation.
|
||||
RUN npm run build
|
||||
|
||||
# Create final image
|
||||
FROM apify/actor-node-playwright-chrome:20
|
||||
|
||||
# Copy only built JS files from builder image
|
||||
COPY --from=builder --chown=myuser /home/myuser/dist ./dist
|
||||
|
||||
# Copy just package.json and package-lock.json
|
||||
# to speed up the build using Docker layer cache.
|
||||
COPY --chown=myuser 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
|
||||
|
||||
# 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 --chown=myuser . ./
|
||||
|
||||
|
||||
# Run the image. If you know you won't need headful browsers,
|
||||
# you can remove the XVFB start script for a micro perf gain.
|
||||
CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod --silent
|
8
README.md
Normal file
8
README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Crawlee + PlaywrightCrawler + TypeScript project
|
||||
|
||||
This template is a production ready boilerplate for developing with `PlaywrightCrawler`. Use this to bootstrap your projects using the most up-to-date code.
|
||||
|
||||
If you're looking for examples or want to learn more visit:
|
||||
|
||||
- [Documentation](https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler)
|
||||
- [Examples](https://crawlee.dev/docs/examples/playwright-crawler)
|
3771
package-lock.json
generated
Normal file
3771
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
package.json
Normal file
26
package.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "crawlee-russellcountyva.us",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"description": "This is an example of a Crawlee project.",
|
||||
"dependencies": {
|
||||
"crawlee": "^3.0.0",
|
||||
"playwright": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@apify/tsconfig": "^0.1.0",
|
||||
"tsx": "^4.4.0",
|
||||
"typescript": "~5.4.0",
|
||||
"@types/node": "^20.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "npm run start:dev",
|
||||
"start:prod": "node dist/main.js",
|
||||
"start:dev": "tsx src/main.ts",
|
||||
"build": "tsc",
|
||||
"test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1",
|
||||
"postinstall": "npx crawlee install-playwright-browsers"
|
||||
},
|
||||
"author": "It's not you it's me",
|
||||
"license": "ISC"
|
||||
}
|
15
src/main.ts
Normal file
15
src/main.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
// For more information, see https://crawlee.dev/
|
||||
import { PlaywrightCrawler, ProxyConfiguration } from 'crawlee';
|
||||
|
||||
import { router } from './routes.js';
|
||||
|
||||
const startUrls = ['https://crawlee.dev'];
|
||||
|
||||
const crawler = new PlaywrightCrawler({
|
||||
// proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
|
||||
requestHandler: router,
|
||||
// Comment this option to scrape the full website.
|
||||
maxRequestsPerCrawl: 20,
|
||||
});
|
||||
|
||||
await crawler.run(startUrls);
|
21
src/routes.ts
Normal file
21
src/routes.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { createPlaywrightRouter } from 'crawlee';
|
||||
|
||||
export const router = createPlaywrightRouter();
|
||||
|
||||
router.addDefaultHandler(async ({ enqueueLinks, log }) => {
|
||||
log.info(`enqueueing new URLs`);
|
||||
await enqueueLinks({
|
||||
globs: ['https://crawlee.dev/**'],
|
||||
label: 'detail',
|
||||
});
|
||||
});
|
||||
|
||||
router.addHandler('detail', async ({ request, page, log, pushData }) => {
|
||||
const title = await page.title();
|
||||
log.info(`${title}`, { url: request.loadedUrl });
|
||||
|
||||
await pushData({
|
||||
url: request.loadedUrl,
|
||||
title,
|
||||
});
|
||||
});
|
12
tsconfig.json
Normal file
12
tsconfig.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"extends": "@apify/tsconfig",
|
||||
"compilerOptions": {
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"target": "ES2022",
|
||||
"outDir": "dist",
|
||||
"noUnusedLocals": false,
|
||||
"lib": ["DOM"]
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user