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
12
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.
- 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);