Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Initial development

Jan Curnd7ca00234cb0
diff --git a/.eslintrc b/.eslintrc
deleted file mode 100644
index a84546062..000000000
--- a/.eslintrc
+++ /dev/null
@@ -1,17 +0,0 @@
-root: true
-
-env:
- es6: true
- node: true
- browser: true
- mocha: true
-
-ecmaFeatures:
- modules: true
-
-extends:
- "airbnb"
-
-rules:
- quotes: 0
- func-names: 0
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 000000000..a9cdec42a
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,25 @@
+{
+ "extends": "airbnb-base",
+ "plugins": [
+ "import",
+ "promise"
+ ],
+ "rules": {
+ "indent": ["error", 4],
+ "no-underscore-dangle": [2, {
+ "allow": ["_id"]
+ }],
+ "no-use-before-define": 0,
+ "no-param-reassign": 0,
+ "consistent-return": 0,
+ "array-callback-return": 0,
+ "arrow-body-style": 0,
+ "no-plusplus": 0,
+ "strict": ["error", "global"],
+ "max-len": ["error", 150],
+ "no-undef": 0,
+ "func-names": 0,
+ "import/prefer-default-export": 0,
+ "import/no-absolute-path": 0
+ }
+}
diff --git a/build/index.js b/build/index.js
index 756c7c865..f26244dba 100644
--- a/build/index.js
+++ b/build/index.js
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-var Person = (function () {
+var Person = function () {
function Person(name, age) {
_classCallCheck(this, Person);
@@ -29,7 +29,6 @@ var Person = (function () {
}]);
return Person;
-})();
+}();
-exports["default"] = Person;
-module.exports = exports["default"];
\ No newline at end of file
+exports.default = Person;
\ No newline at end of file
diff --git a/index.js b/index.js
deleted file mode 100644
index 5629fed0b..000000000
--- a/index.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*!
- * Apifier SDK for JavaScript.
- *
- * This is a work in progress.
- *
- * Author: Jan Curn ([email protected])
- * Copyright(c) 2016-2017 Apifier. All rights reserved.
- *
- */
-"use strict";
-
-console.log("Apifier SDK for JavaScript");
-console.log("Copyright(c) 2016-2017 Apifier. All rights reserved.");
-console.log("");
-
-
-
-//exports.
-
-
-
-
-
-
-
-
-const http = require('http');
-const fs = require('fs'); // yyyyyy
-
-console.log("Hello world !!!");
-console.dir(process.env);
-
-setTimeout( function() {
-
- const server = http.createServer((req, res) => {
- res.statusCode = 200;
- res.setHeader('Content-Type', 'text/plain');
- res.end('Hello World\n');
- console.log("Received message!!!");
- // console.dir(req);
- });
- server.listen(process.env.APIFIER_INTERNAL_PORT|0, function() {
- console.log("Listening on port : " + (process.env.APIFIER_INTERNAL_PORT|0));
- fs.writeFileSync("/apifier-truncate-when-ready", "");
- });
-
-}, 10000);
diff --git a/package.json b/package.json
index 3756cb0d9..9d8e1cc4f 100644
--- a/package.json
+++ b/package.json
@@ -1,52 +1,55 @@
{
- "name": "apifier",
- "version": "0.0.3",
- "description": "Apifier SDK for JavaScript",
- "main": "index.js",
- "keywords": [
- "apifier",
- "crawler",
- "scraper"
- ],
- "author": {
- "name": "Apifier",
- "email": "[email protected]",
- "url": "https://www.apifier.com"
- },
- "contributors": [
- "Jan Curn <[email protected]>"
- ],
- "license": "Apache-2.0",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/apifier/apifier-sdk-js"
- },
- "bugs": {
- "url": "https://github.com/apifier/apifier-sdk-js/issues"
- },
- "homepage": "https://github.com/apifier/apifier-sdk-js#readme",
- "scripts": {
- "test": "mocha --compilers js:babel-core/register --recursive",
- "test-cov": "babel-node isparta cover --report html --report text node_modules/.bin/_mocha",
- "build": "babel src --out-dir build",
- "clean": "rm -rf build",
- "lint": "eslint src test"
- },
- "dependencies": {},
- "devDependencies": {
- "babel-core": "^6.1.21",
- "babel-eslint": "^7.2.2",
- "babel-preset-es2015": "^6.1.18",
- "babel-preset-stage-0": "^6.1.18",
- "chai": "^3.4.1",
- "eslint": "^3.19.0",
- "eslint-config-airbnb": "^14.1.0",
- "eslint-plugin-react": "^6.10.3",
- "eslint-config-airbnb-base": "^11.1.0",
- "eslint-plugin-import": "^2.2.0",
- "eslint-plugin-jsx-a11y": "^4.0.0",
- "eslint-plugin-promise": "^3.4.2",
- "isparta": "^4.0.0",
- "mocha": "^3.2.0"
- }
+ "name": "apifier",
+ "version": "0.0.4",
+ "description": "Apifier SDK for JavaScript",
+ "main": "build/index.js",
+ "keywords": [
+ "apifier",
+ "crawler",
+ "scraper"
+ ],
+ "author": {
+ "name": "Apifier",
+ "email": "[email protected]",
+ "url": "https://www.apifier.com"
+ },
+ "contributors": [
+ "Jan Curn <[email protected]>"
+ ],
+ "license": "Apache-2.0",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/apifier/apifier-sdk-js"
+ },
+ "bugs": {
+ "url": "https://github.com/apifier/apifier-sdk-js/issues"
+ },
+ "homepage": "https://github.com/apifier/apifier-sdk-js#readme",
+ "scripts": {
+ "test": "mocha --compilers js:babel-core/register --recursive",
+ "test-cov": "babel-node isparta cover --report html --report text node_modules/.bin/_mocha",
+ "build": "babel src --out-dir build",
+ "clean": "rm -rf build",
+ "lint": "eslint src test"
+ },
+ "dependencies": {
+ "underscore": "^1.8.3"
+ },
+ "devDependencies": {
+ "babel-core": "^6.1.21",
+ "babel-eslint": "^7.2.2",
+ "babel-preset-es2015": "^6.1.18",
+ "babel-preset-stage-0": "^6.1.18",
+ "babel-cli": "^6.6.5",
+ "chai": "^3.4.1",
+ "eslint": "^3.19.0",
+ "eslint-config-airbnb": "^14.1.0",
+ "eslint-plugin-react": "^6.10.3",
+ "eslint-config-airbnb-base": "^11.1.0",
+ "eslint-plugin-import": "^2.2.0",
+ "eslint-plugin-jsx-a11y": "^4.0.0",
+ "eslint-plugin-promise": "^3.4.2",
+ "isparta": "^4.0.0",
+ "mocha": "^3.2.0"
+ }
}
diff --git a/src/actor.js b/src/actor.js
new file mode 100644
index 000000000..46fffe50b
--- /dev/null
+++ b/src/actor.js
@@ -0,0 +1,40 @@
+import http from 'http';
+import fs from 'fs';
+
+
+export default {
+
+ main: (handler) => {
+ if (!handler || typeof (handler) !== 'function') {
+ throw new Error('Handler function must be provided as a parameter');
+ }
+ const serverPort = parseInt(process.env.APIFIER_INTERNAL_PORT, 10);
+ if (!(serverPort > 0 && serverPort < 65536)) {
+ throw new Error('APIFIER_INTERNAL_PORT environment variable must be a value from 1 to 65535.');
+ }
+
+ const watchFileName = process.env.APIFIER_WATCH_FILE;
+
+ const wrappedHandler = (req, res) => {
+ try {
+ handler(req, res);
+
+ // close response if not yet
+ } catch (e) {
+ console.log( 'Received message!!!' );
+ res.statusCode = 200;
+ res.setHeader( 'Content-Type', 'text/plain' );
+ res.end('Hello World\n');
+ }
+ };
+
+ const server = http.createServer(wrappedHandler);
+
+ server.listen(serverPort, () => {
+ console.log(`Listening on port ${serverPort}`);
+ if (watchFileName) fs.writeFileSync(watchFileName, '');
+ });
+ },
+
+};
+
diff --git a/src/index.js b/src/index.js
index ab6854608..c737c807a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,16 +1,8 @@
-class Person {
- constructor(name, age) {
- this.name = name;
- this.age = age;
- }
+import _ from 'underscore';
+import Actor from './actor';
- getName() {
- return this.name;
- }
- getAge() {
- return this.age;
- }
-}
+const Apifier = {};
+_.extend(Apifier, Actor);
-export default Person;
+export default Apifier;
diff --git a/test/Counter.spec.js b/test/Counter.spec.js
deleted file mode 100644
index 47e041f8b..000000000
--- a/test/Counter.spec.js
+++ /dev/null
@@ -1,22 +0,0 @@
-import { expect } from 'chai';
-import Person from '../src/index.js';
-
-describe("Person", () => {
- let person;
-
- before(() => {
- person = new Person('Cam', 99);
- });
-
- after(() => {
- person = undefined;
- });
-
- it("should return name", function() {
- expect(person.getName()).to.equal('Cam');
- });
-
- it("should return age", function() {
- expect(person.getAge()).to.equal(99);
- });
-});
diff --git a/test/actor.js b/test/actor.js
new file mode 100644
index 000000000..0a97e6c2a
--- /dev/null
+++ b/test/actor.js
@@ -0,0 +1,37 @@
+import { expect } from 'chai';
+import Apifier from '../src/index';
+
+/* global process */
+
+describe('Apifier.main()', () => {
+ it('should throw on invalid args', () => {
+ process.env.APIFIER_INTERNAL_PORT = 1234;
+ expect(() => {
+ Apifier.main();
+ }).to.throw(Error);
+ });
+
+ it('should throw on invalid env vars', () => {
+ const fn = () => {
+ Apifier.main(() => {});
+ };
+
+ process.env.APIFIER_INTERNAL_PORT = null;
+ expect(fn).to.throw(Error);
+
+ process.env.APIFIER_INTERNAL_PORT = '';
+ expect(fn).to.throw(Error);
+
+ process.env.APIFIER_INTERNAL_PORT = 0;
+ expect(fn).to.throw(Error);
+
+ process.env.APIFIER_INTERNAL_PORT = 65536;
+ expect(fn).to.throw(Error);
+ });
+
+ it('should work well', () => {
+ process.env.APIFIER_INTERNAL_PORT = 12345;
+ // TODO: use watch file
+ Apifier.main(() => {});
+ });
+});