{"id":20671159,"url":"https://github.com/allnulled/web2os","last_synced_at":"2025-10-17T23:03:55.912Z","repository":{"id":98547103,"uuid":"132267848","full_name":"allnulled/web2os","owner":"allnulled","description":"Scrap the web asynchronously in live, reusing Node.js, all in one file, with a few lines!","archived":false,"fork":false,"pushed_at":"2018-06-25T11:43:51.000Z","size":327,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-25T21:44:34.732Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allnulled.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-05T17:02:10.000Z","updated_at":"2022-09-21T17:26:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"7d9535ed-b0c4-4c5e-a611-4ca9c4246fdb","html_url":"https://github.com/allnulled/web2os","commit_stats":{"total_commits":39,"total_committers":1,"mean_commits":39.0,"dds":0.0,"last_synced_commit":"14065859ebfe3720d44c43489029bf8f051da1df"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Fweb2os","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Fweb2os/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Fweb2os/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allnulled%2Fweb2os/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allnulled","download_url":"https://codeload.github.com/allnulled/web2os/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242889681,"owners_count":20202007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T20:25:33.311Z","updated_at":"2025-10-17T23:03:50.874Z","avatar_url":"https://github.com/allnulled.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":" \n\n# web2os\n\n![](https://img.shields.io/badge/web2os-v1.1.0-green.svg) ![](https://img.shields.io/badge/tests-passing-green.svg) ![](https://img.shields.io/badge/coverage-85%25-green.svg)\n\nScrap the web asynchronously in live, reusing Node.js, all in one file, with a few lines! From the web to your operative system (web2os), easily!\n\n*Based on [Electron](https://github.com/electron/electron).*\n\n## 1. Installation\n\n~$ `npm install -s web2os`\n\n## 2. Usage\n\n#### 2.1. How to run `web2os` scripts\n\nIf you installed [Electron](https://github.com/electron/electron) globally, you can:\n\n~$ `electron myScript.js`\n\n*Note: if you have problems installing **Electron** globally, use the flag `--unsafe-perm=true`.*\n\nIf you did not install [Electron](https://github.com/electron/electron) globally, you can, instead:\n\n~$ `./node_modules/.bin/electron myScript.js`\n\n## 3. Examples\n\nAs all the API of `web2os` module is chainable (all the methods can be called one after the other), these are some examples:\n\n#### Example 1: scrap Google's main page title and put it into a file:\n\n```js\nrequire(\"web2os\")\n .create()\n .open(\"https://www.google.com\")\n .onWeb((done, error) =\u003e {done(document.title);})\n .onOs((done, error, data) =\u003e {\n   require(\"fs\").writeFileSync(\"Google title.txt\", data, \"utf8\");\n   done();\n })\n .run(() =\u003e {\n   console.log(\"DONE!\");\n });\n```\n\n##### Example 2: scrap Github's main page title (this time headlessly, so without seeing the browser) and put it into a file:\n\n```js\nrequire(\"web2os\")\n .create({\n   browser: {show: false}\n })\n .open(\"https://www.github.com\")\n .onWeb((done, error) =\u003e {done(document.title);})\n .onOs((done, error, data) =\u003e {\n   require(\"fs\").writeFileSync(\"Google title.txt\", data, \"utf8\");\n   done();\n })\n .run(() =\u003e {\n   console.log(\"DONE!\");\n });\n```\n##### Example 3: scrap multiple URLs the same way:\n\n```js\nconst web2osInstance = require(\"web2os\").create({});\nconst links = [\n \"https://www.google.com\", \n \"https://www.github.com\", \n \"https://stackoverflow.com/\"\n];\nconst file = __dirname + \"/titles.txt\";\nconst fs = require(\"fs\");\nconst data = {titles: []};\nlinks.forEach((link) =\u003e {\n web2osInstance\n   .open(link)\n   .onWeb((done, error) =\u003e {\n     done(document.title);\n   }).onOs((done, error, title) =\u003e {\n     fs.appendFileSync(file, title+\"\\n\", \"utf8\");\n     done();\n   });\n});\nweb2osInstance.run(() =\u003e {\n fs.readFileSync(file).toString()\n});\n```\n\n## 4. API Reference\n\n\n\n\n \n\n\n----\n\n### `require(\"web2os\").create(optionsParam)`\n\n**Type:** `{Function}`\n\n**Param:** `{Object} optionsParam`. Object with the options we want to provide for the current web2os instance.\n\nAccepted parameters are:\n\n - **abortOnRejectedPromise**: `{Boolean}`. Defaults to `true`. This means that `{web2os}` will stop the execution when a promise (from `onWeb` or `onOs` callbacks) is rejected.\n\n - **browser**: `{Object}`. Parameters for the {BrowserWindow} Electron object. For more info, go to: https://github.com/electron/electron/blob/master/docs/api/browser-window.md#class-browserwindow\n\n - **openDevTools**: `{Boolean}`. Specifies if the openDevTools should be opened or not. Default: false.\n\n\n**Returns:** `{Object} chainable`. Object that has all the methods available for `{web2os}` scraps.\n\n**Description:** Creates an instance of `{web2os}`, and returns its chainable methods as an `{Object}` that we will call the `chainable`.\n\n\n\n \n\n\n----\n\n### `web2os`\n\n**Type:** `{Object}` Object returned by `require(\"web2os\").create(...);`. It represents a `{web2os}` instance.\n\n**Description:** Object that is going to be returned by the methods it has, in order\nto make them chainable. It also holds the `internals` property, which has some \nuseful data for the `{web2os}` instance.\n\n\n\n \n\n\n----\n\n### `web2os#internals`\n\n**Type:** `{Object}`\n\n**Description:** Contains some useful data for the `{web2os}` instance.\n\n\n\n \n\n\n----\n\n### `web2os#internals.tasks`\n\n**Type:** `{Array}`\n\n**Description:** Holds all the tasks (asynchronous functions) that have been requested \nto this `{web2os}` instance. The tasks that are dispatched (or being dispatched) will\nnot appear in this array.\n\n\n\n \n\n\n----\n\n### `web2os#internals.options`\n\n**Type:** `{Object}`\n\n**Description:** Contains all the parameters of the current `{web2os}` instance.\nThis object is deeply extended by the parameter passed to the \n`{web2os}.create(~)` method.\n\nBy default, its value is:\n\n```js\n{\n openDevTools: false,\n browser: {\n   // show: false,\n   width: 800,\n   height: 600,\n   webPreferences: {\n     nodeIntegration: false\n   }\n },\n abortOnRejectedPromise: true\n}\n```\nAlso, you can pass a `onError` function, to handle the errors by default.\n\n\n\n\n\n \n\n\n----\n\n### `web2os#open`\n\n**Type:** `{Function}`\n\n**Parameter:** `{String}` `url`. URL to be opened by the current `{web2os}` instance.\n\n**Returns:** `{Object}` chainables.\n\n**Description:** Adds a task that opens the provided URL (it can be a `\"file://\"` URI too)\n\n\n\n \n\n\n----\n\n### `web2os#onWeb`\n\n**Type:** `{Function}`\n\n**Param:** {Function:async || String} fnParam. Asynchronous function (this means that it will\nreceive as parameters: {1:Function:resolve}, {2:Function:reject}) that will be applied\nto the Web Environment of the current `{web2os}` instance. Must be resolved or rejected.\nThe parameter can also be a string, which should contain the code of an asynchronous \nfunction.\n\n**Param:** {Boolean} isSync. Default: false. Set to true to pass simple code, and it will not\nbe wrapped in a {Promise}. By default, the fnParam is wrapped in a Promise.\n\n**Returns:** `{Object}` chainables\n\n**Description:** Adds a task that executes an asynchronous function in the Web Environment.\nIn this environment, you are working with the JavaScript of the browser, and so, you can\nmanipulate the DOM, do AJAX calls, or whatever. This function can return, through the \n`resolve` ({1:Function:resolve}) parameter some data, and if the next chained call is an\n`onOs(func)`, the callback it handles will receive this data, appended as a new parameter.\nThis way, you can pass data from the Web Environemnt to the OS Environment, and manage it\nlocally.\n\n\n\n \n\n\n----\n\n### `web2os#onOs(fn:Function:async)`\n\n**Type:** `{Function}`\n\n**Param:** {Function:async} fn. Asynchronous function (this means that it will\nreceive as parameters: \n- **param 1:** `{Function:resolve}`\n- **param 2:** `{2:Function:reject}`\nboth of which work as a typical JavaScript `Promise`) that will be applied \nto the OS Environment.\nMoreover, if the previous chained call was an `onWeb` call, and\nit was resolved with some data as parameter, a 3rd parameter will be passed to this\nasynchronous function that is going to be executed in our OS Environment. \nThat parameter\nwill contain the data returned by the previous `onWeb` asynchronous call. Otherwise, \nonly the `resolve` and `reject` functions will be passed as parameters.\n\n**Returns:** `{Object}` `chainables`.\n\n**Description:** Adds a task that executes an asynchronous function in the OS Environment.\nIn this environment, you are working with the JavaScript of Node.js, and so, you can\naccess to any npm or node modules available in your current context (to read and write files, \nstart processes, manage databases, etc.).\n\n\n\n \n\n\n----\n\n### `web2os#run(doneRun:Function)`\n\n**Type:** `{Function}`\n\n**Param:** `{Function}` `doneRun` (Optional). Function that will be executed once the `run`\nfunction ended.\n\n**Returns:** `{Object}` `chainables`\n\n**Description:** This function starts running all the tasks acumulated until it is called.\n\n\n\n \n\n\n\n\n## 5. Tests, coverage and documentation generation\n\n#### 5.1. Tests and coverage\n\nYou can make the tests pass and generate automatically the coverage by typing:\n\n~$ `npm run test`\n\nYou can clean the generated coverage reports by typing:\n\n~$ `npm run clean`\n\n#### 5.2. Documentation\n\nYou can regenerate the documentation typing:\n\n~$ `npm run docs`\n\nThe generated docs will be dumped directly from `src/web2os.js` to `README.md` file, in Markdown format, and from javadoc comments.\n\n## 6. Conclusion\n\nThis has turned into a promising clean API to do web-scraping comfortably, and in a fast, reliable way, because you can attack to applications that are loaded by client-side frameworks like Angular or React, which require a DOM processing by the browser previously to proceed to the scrap.\n\nConsider the fact that you can:\n\n1. Use database NPM modules to insert the data that you collect from the web directly to your database, you can even use ORMs to do it effortlessly.\n\n2. See the current progression of the scraps.\n\n3. Do multiple simultaneous scraps in the same script even.\n\n4. Automate tests or demonstration of products.\n\n5. Take profit of all the Node.js modules to do your scraps, tests or whatever.\n\n6. Scrap the web asynchronously, with a browser environment executing all the JavaScript needed to reach the data you want.\n\nBut also, you can see how a Chromium browser does all of this in live, interact with it by hand in the moment, and it is very simple to use because you only have to use the technologies you already know, the JavaScript of the browser and Node.js! \n\nHappy scraping!\n\n*Take into account that I am the developer of the NaturalScript programming language, and I have been working on Open Source projects since I know that Microsoft is not available to give 5.000 dollars to programming languages that come nearer to natural language, and they do not even want to give explanations about their reasons... Well, Microsoft, Google, Intel and Oracle, neither of them are capable to answer a request by a simple novice developer who is giving big part of its time to the Open Source community.*\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallnulled%2Fweb2os","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallnulled%2Fweb2os","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallnulled%2Fweb2os/lists"}