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

lead-scraping

v1.0.1

Published

A web scraping library for extracting phone numbers, emails, social links, and website info.

Downloads

9

Readme

LeadScraper

LeadScraper is an efficient web scraping library for extracting contact information and website details. It's designed to be easy to use while providing robust functionality for gathering leads from websites.

Features

  • Extract phone numbers, email addresses, and social media links
  • Gather website information (domain, creation year, platform)
  • Caching support to improve performance and reduce redundant scraping
  • TypeScript support for enhanced development experience
  • Built with performance in mind using got-scraping

Installation

Install LeadScraper using npm:

npm install lead-scraper
bun add lead-scraper

Usage

Basic Usage

import LeadScraper from 'lead-scraper';

const scraper = new LeadScraper();

const url = 'https://example.com';
scraper.scrape(url).then(data => {
  console.log(data);
});

With Caching

const scraper = new LeadScraper({
    cache: true,
    cacheOptions: {
        maxSize: 1000,  // Store up to X items in memory
        maxAge: 7 * 24 * 60 * 60 * 1000  // Cache items for up to 7 days
    }
});

const url = 'https://example.com';
scraper.scrape(url).then(data => {
  console.log(data);
});
// Clear the cache if needed
await scraper.clearCache();

Individual Methods

const scraper = new LeadScraper();

const url = 'https://example.com';
await scraper.loadPage(url);

const emails = scraper.getEmails(url);
const phones = scraper.getPhones(url);
const socials = scraper.getSocials(url);
const websiteInfo = await scraper.getWebsiteInfo(url);

console.log({ emails, phones, socials, websiteInfo });

API

new LeadScraper(options)

Creates a new LeadScraper instance.

  • options.cache (boolean): Enable caching (default: false)
  • options.expiration (string): Cache expiration time (default: '6m')

scraper.scrape(url: string): Promise<ScrapeResult>

Scrapes the given URL for all available information.

scraper.loadPage(url: string): Promise<boolean>

Loads the page content. Must be called before using individual methods if not using scrape().

scraper.getEmails(url: string): string[]

Returns an array of email addresses found on the page.

scraper.getPhones(url: string): string[]

Returns an array of phone numbers found on the page.

scraper.getSocials(url: string): Record<string, string>

Returns an object with social media links found on the page.

scraper.getWebsiteInfo(url: string): Promise<Record<string, string>>

Returns website information including domain, creation year, and platform.

Caching

When caching is enabled, scraped data is stored locally to avoid redundant scraping of the same URLs. The cache expiration can be set using the following format:

  • h: Hours (e.g., '24h' for 24 hours)
  • d: Days (e.g., '7d' for 7 days)
  • m: Months (e.g., '1m' for 1 month)

License

This project is licensed under the ISC License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Disclaimer

Ensure you have permission to scrape websites and always respect robots.txt files and rate limits. Use this library responsibly and in accordance with the terms of service of the websites you are scraping. sed on your specific implementation or add more examples if needed.