├── README.md ├── WPdown.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | # Wpdown 2 | a script to download a webpage 3 | This script cant read some sites because thay are has a bot blocker 4 | dont forget to write the link with https or http 5 | If you dont enter them the script make a error and not understand and analyze the url 6 | -------------------------------------------------------------------------------- /WPdown.js: -------------------------------------------------------------------------------- 1 | var https = require("https"); 2 | var http = require("http"); 3 | var fs = require("fs"); 4 | var url = require("url"); 5 | var chalk = require("chalk"); 6 | console.log(chalk.green(`██╗ ██╗██████╗ ██████╗ ██████╗ ██╗ ██╗███╗ ██╗ 7 | ██║ ██║██╔══██╗██╔══██╗██╔═══██╗██║ ██║████╗ ██║ 8 | ██║ █╗ ██║██████╔╝██║ ██║██║ ██║██║ █╗ ██║██╔██╗ ██║ 9 | ██║███╗██║██╔═══╝ ██║ ██║██║ ██║██║███╗██║██║╚██╗██║ 10 | ╚███╔███╔╝██║ ██████╔╝╚██████╔╝╚███╔███╔╝██║ ╚████║ 11 | ╚══╝╚══╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══╝╚══╝ ╚═╝ ╚═══╝ 12 | `)); 13 | console.log(chalk.green('welcome to WPdown script we downliad your link and write it on a file for you to use it dont forget to enter link with http:// or https:// it need to find and read your link')); 14 | process.stdout.write(chalk.red('>>')); 15 | process.stdout.write(chalk.green("enter the link:")); 16 | process.stdin.on("data",function(data){ 17 | var link = new URL(data.toString()); 18 | var options = { 19 | hostname:link.hostname, 20 | port:0, 21 | path:link.pathname, 22 | method:"GET" 23 | } 24 | if(link.protocol == "https:"){ 25 | options.port = 443; 26 | var part = 2; 27 | var data = ""; 28 | var req = https.request(options,function(res){ 29 | console.log("reading..."); 30 | console.log(`status:${res.statusCode}`); 31 | console.log("headers:%j",res.headers); 32 | res.once("data",function(chunk){ 33 | console.log("first chunk downloaded"); 34 | }); 35 | res.on("data",function(chunk){ 36 | console.log(`part${part} downloaded`); 37 | data += chunk; 38 | part++ 39 | }); 40 | res.on("end",function(){ 41 | console.log("download complated... \n enter the name you like to be a file name"); 42 | fs.writeFile(`${link.hostname}.html`,data,function(err){ 43 | if(err){ 44 | throw err; 45 | }else{ 46 | console.log("file created now you can used"); 47 | } 48 | }); 49 | 50 | }); 51 | }); 52 | req.on("error",function(err){ 53 | console.log("download be errored..."); 54 | console.log(`error:${err.message}`); 55 | }); 56 | req.end(); 57 | }else if(link.protocol == "http:"){ 58 | options.port = 80; 59 | var part = 2; 60 | var data = ""; 61 | var req = http.request(options,function(res){ 62 | console.log("reading..."); 63 | console.log(`status:${res.statusCode}`); 64 | console.log("headers:%j",res.headers); 65 | res.once("data",function(chunk){ 66 | console.log("first chunk downloaded"); 67 | }); 68 | res.on("data",function(chunk){ 69 | console.log(`part${part} downloaded`); 70 | data += chunk; 71 | part++ 72 | }); 73 | res.on("end",function(){ 74 | console.log("download complated... \n enter the name you like to be a file name"); 75 | fs.writeFile(`${link.hostname}.html`,data,function(err){ 76 | if(err){ 77 | throw err; 78 | }else{ 79 | console.log("file created now you can used"); 80 | } 81 | }); 82 | 83 | }); 84 | }); 85 | req.on("error",function(err){ 86 | console.log("download be errored..."); 87 | console.log(`error:${err.message}`); 88 | }); 89 | req.end(); 90 | }else{ 91 | console.log("the link not supported"); 92 | } 93 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wpdown", 3 | "version": "1.0.0", 4 | "description": "a script to download a webpage", 5 | "main": "WPdown.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/nightcode-dev/Wpdown.git" 12 | }, 13 | "keywords": [ 14 | "WebPageDownloader", 15 | "Script", 16 | "Download", 17 | "WebPage" 18 | ], 19 | "author": "night code", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/nightcode-dev/Wpdown/issues" 23 | }, 24 | "homepage": "https://github.com/nightcode-dev/Wpdown#readme" 25 | } 26 | --------------------------------------------------------------------------------