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.

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
	resultTypes: [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

Disclaimer

This is not sponsored, supported, or affiliated with Google.

The source code within this repository is intended solely for educational & research purposes. The author (typicalninja) & contributors takes NO responsibility for any issues that arise from its use. Your discretion in usage is advised.

Tests

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

pnpm run test

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 ★

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •