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

serp-parser-v1

v1.0.7

Published

This is a simple Google SERP (Search Engine Results Page) parser built with Node.js , Typescript and Cheerio. It extracts organic search results, paid ads, and Product Listing Ads (PLA) from Google search results HTML content.

Downloads

34

Readme

SERP PARSER

This is a simple Google SERP (Search Engine Results Page) parser built with Node.js , Typescript and Cheerio. It extracts organic search results, paid ads, and Product Listing Ads (PLA) from Google search results HTML content.

Usage - Google SERP extraction

GoogleSERP accepts html content as input and provides the parsed result as output.

  1. Clone the repository .

https://github.com/ScraperPlatform/serp-parser.git

2.Install Dependencies


npm install

Create an instance of GoogleSERP with the HTML content of a Google search results page:

import { GoogleSERP } from 'google.ts' 

const googleSERP = new GoogleSERP(htmlContent);


For mobile usage import the GoogleMobileSERP class from gogole-mobile.ts.

import { GoogleMobileSERP } from 'google-mobile.ts' 

const googleMobileSERP = new GoogleSERP(htmlContent);

console.log('Keyword:', googleMobileSERP.serp.keyword);
console.log('PLA Results:', googleMobileSERP.serp.pla);
console.log('Organic Results:', googleMobileSERP.serp.organic);
console.log('Paid Results:', googleMobileSERP.serp.paid);

It will return interface like this .

 interface StructuredData {
    page: number;
    results: {
      pla?: Pla[];
      paid?: Paid[];
      organic?: Organic[];
    };
  }
  

Testing

For running tests run

npm test 

This will run the file GoogleSERP.test.ts present in tests/google directory.This will test the app with taking sample.html as input , also present in the same directory .

Testing Against Your Input

If you want to test the application with custom html content you can create a file src directory for testing and a sample html file for testing . 1- Eg. Create sampleTest.ts in src directory and also create sample.html file in same directory and put any html content you want to test.

Paste this code in sampleTest.ts

import * as fs from 'fs';
import { GoogleSERP } from './google';

// Read the contents of sample.html
const htmlContent = fs.readFileSync('sample.html', 'utf8');

// Create an instance of GoogleSERP with the HTML content
const googleSERP = new GoogleSERP(htmlContent);

2- Change directory in to src and run

npx ts-node sampleTest.ts

3-You can check the output in the terminal .

For testing mobile results replicate the exact process . Paste this in sampleTest.ts

import * as fs from 'fs';
import { GoogleMobileSERP } from './google-mobile';

// Read the contents of sample.html
const htmlContent = fs.readFileSync('sample.html', 'utf8');

// Create an instance of GoogleMobileSERP with the HTML content
const googleSERP = new GoogleMobileSERP(htmlContent);