Skip to content

typicalninja/google-sr

Repository files navigation

google-sr

Scrape Google search results using JavaScript / TypeScript

testing workflow GitHub Repo stars Monthly downloads CodeFactor codecov Discord

Install

Not supported in browser environments.

If you are using CommonJS, please read the important notice about future ESM-only support.

npm install google-sr
# For pnpm/yarn/bun:
pnpm add google-sr
yarn add google-sr
bun add google-sr

Usage

import { search, OrganicResult, TranslateResult, ResultTypes } from "google-sr";

const results = await search({
	query: "translate hello to japanese",
	// Explicitly specify the results you want
	parsers: [TranslateResult, OrganicResult],
});

console.log(results[0].type === ResultTypes.TranslateResult); // true
console.log(results); // see below

Output

[
  {
    // type property is present in all results
    type: 'TRANSLATE',
    sourceLanguage: 'English (detected)',
    translationLanguage: 'Japanese',
    sourceText: 'hello',
    translatedText: 'こんにちは'
  },
  {
    type: 'ORGANIC',
    link: '...',
    description: "Konnichiwa – ...",
    title: '18 ...'
  },
  // ... and more
]

Additional examples can be found in apps/examples directory

Notice for CommonJS users

This package currently includes both CommonJS (CJS) and ES Modules (ESM) builds.

Starting with v7.x (subject to change), we plan to drop CJS support and publish only ESM-only builds.

Why ESM-only going forward?

While Node.js v20 already supports ESM well, we will wait until its End-of-Life before removing CJS to give users and tooling more time to transition.

Note: This applies only to Node.js users, other runtimes like Bun and Deno already support ESM natively

See this gist for future migration tips and our GitHub discussion for more details.

Tests

Tests are written using vitest and can be run by using the test script.

pnpm run test

Disclaimer

This project is not sponsored, endorsed, or affiliated with Google in any way.

This repository is provided "as is" without warranty of any kind and is intended solely for educational and research purposes. The authors and contributors assume no responsibility for any issues, damages, or losses that may arise from its use.

By using this project, you acknowledge that you are solely responsible for complying with applicable laws and platform Terms of Service. Use at your own discretion and risk.

License

This repository and the code inside it is licensed under the Apache-2.0 License. Read LICENSE for more information.


Want to support the project? Star it on GitHub ★