npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dextractor

v2.0.2

Published

Dextractor is a tool to extract links from within a given URL, save them inside a text file and download the files from the links that actually end to a file.

Downloads

19

Readme

Dextractor

Dextractor is a tool to extract links from within a given URL, save them inside a text file and download the files from the links that actually end to a file.

Installation

I assume that you have NodeJS already installed on your machine.

1. Simply cd to the root of your NodeJS project and run:

npm install dextractor

2. Done!


Usage

1. Simply require the module inside your project:

const dextractor = require("dextractor");

Or use the experimental module approach if you wish:

import dextractor from "dextractor";

2. There are four methods available to use. The available methods are as below:

> saveLinks(url, path?, callback?)

This method only saves the links that appear inside of a given URL into a text file in [path that you specify or ./export if you don't specify any path]/[Given URL separated with underlines instead of forward slashes]/links/links.txt.

Parameters:

Parameter | Type | Description ---------- | ------ | -------------- url | String | The URL that you wish to perform the dextraction on. path | String | [Optional] The path to save the downloaded files and/or saved links in it. If no path is specified, ./export/ will be used instead. callback | Function | [Optional] The function to be executed after the dextraction was done. If no function is specified, it will simply print Done! on the console after the job is done.

Example:

const dextractor = require("dextractor");

dextractor.saveLinks("https://example.com", "./example", () => {
  console.log("Alright!");
});

> downloadFiles(url, path?, callback?)

This method only downloads the files in the links appearing inside of the given URL and saves them in a zip file in [path that you specify or ./export if you don't specify any path]/[Given URL separated with underlines instead of forward slashes]/files.zip.

Parameters:

Parameter | Type | Description ---------- | ------ | -------------- url | String | The URL that you wish to perform the dextraction on. path | String | [Optional] The path to save the downloaded files and/or saved links in it. If no path is specified, ./export/ will be used instead. callback | Function | [Optional] The function to be executed after the dextraction was done. If no function is specified, it will simply print Done! on the console after the job is done.

Example:

const dextractor = require("dextractor");

dextractor.downloadFiles("https://example.com", "./example", () => {
  console.log("Alright!");
});

> saveLinksAndDownloadFiles(url, path?, callback?)

This method does the whole job of dextraction. It saves the links that appear inside of the given URL into a text file in [path that you specify or ./export if you don't specify any path]/[Given URL separated with underlines instead of forward slashes]/links/links.txt and then downloads the files in the links appearing inside of the given URL and saves them in a zip file in [path that you specify or ./export if you don't specify any path]/[Given URL separated with underlines instead of forward slashes]/files.zip.

Parameters:

Parameter | Type | Description ---------- | ------ | -------------- url | String | The URL that you wish to perform the dextraction on. path | String | [Optional] The path to save the downloaded files and/or saved links in it. If no path is specified, ./export/ will be used instead. callback | Function | [Optional] The function to be executed after the dextraction was done. If no function is specified, it will simply print Done! on the console after the job is done.

Example:

const dextractor = require("dextractor");

dextractor.saveLinksAndDownloadFiles("https://example.com", "./example", () => {
  console.log("Alright!");
});

> getLinks(url, callback?)

This method only gives you an array of the extracted links from within the given URL. Just simply pass a parameter to your callback and that will be the array of extracted links.

Parameters:

Parameter | Type | Description ---------- | ------ | -------------- url | String | The URL that you wish to perform the dextraction on. callback | Function | [Optional] The function to be executed after the dextraction was done. Note: You should pass a parameter to your callback in order to access the array of extracted links inside of your callback.

Example:

const dextractor = require("dextractor");

dextractor.getLinks("https://example.com", links => {
  links.map(each => {
    console.log(each);
  });
});

Note 1: If you wish to run the dextraction in a synchronous manner, simply pass anything that you wish to be executed after the dextraction inside of a function as a callback to any of the available methods.

Note 2: The downloading feature (downloadFiles and saveLinksAndDownloadFiles methods) only works on the direct and static downloading links e.g. https://example.com/image.png meaning that dynamic download links will not work.

Note 3:: The link extraction feature (saveLinks and saveLinksAndDownloadFiles methods) works properly only on static websites or static file servers. On a dynamic website you might get links to the personal files of the website.


Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

MIT