google-sr

website·Indexed 30 days ago

https://g-sr.vercel.app/

A parser for Google search results that supports multiple result types, including regular search results, currency, translation, dictionary, and time. The documentation covers v3.2.1 of the core library and v0.0.2 of google-sr-selectors, providing guides on basic and advanced usage, custom selectors, and API interfaces such as SearchOptions and SearchResultNode.

Tokens
4.1K
Snippets
37
Records
43
Agent score
74%

What's inside google-sr

  1. Overview of google-sr search scraper

    google-sr is a simple and fast package designed for scraping Google search results. Unlike official Google Search APIs, it does not require an API key to function. It is TypeScript compatible and supports a wide variety of search result types.
  2. Overview of the GSR project for Google search scraping

    The GSR project provides a suite of JavaScript packages designed to scrape Google search results without requiring an API key. It consists of three primary tools: google-sr for programmatic scraping, google-sr-selectors for HTML parsing, and google-that for command-line usage.
  3. Overview of google-sr-selectors

    google-sr-selectors provides a set of HTML selectors designed to parse Google Search results using jQuery-like modules (e.g., cheerio). These selectors are specifically intended for the non-JavaScript version of the Google Search page, which can be accessed by appending &gbv=1 to the search query URL. Note that because Google periodically updates its HTML structure, selectors may occasionally become outdated.
  4. Identify search result types in google-sr

    The google-sr library categorizes search results into different types based on the nature of the query. When processing returned objects, you can check the type property to determine how to handle the data. The supported result types are:
    // Example mapping of query types to ResultTypes
    
    // Organic/Normal search (e.g., "node js")
    // type: ResultTypes.SearchResult
    
    // Translation queries (e.g., "Translate hello to spanish")
    // type: ResultTypes.TranslateResult
    
    // Definition queries (e.g., "define amazing")
    // type: ResultTypes.DictionaryResult
    
    // Time queries (e.g., "what is the current time in uk")
    // type: ResultTypes.TimeResult
    
    // Currency queries (e.g., "Convert 10 usd to cad")
    // type: ResultTypes.CurrencyResult
  5. Install google-sr-selectors

    Install the google-sr-selectors package using npm, pnpm, or yarn.
    # Using npm
    npm i google-sr-selectors
    
    # Using pnpm
    pnpm add google-sr-selectors
    
    # Using yarn
    yarn add google-sr-selectors
  6. Run google-that without global installation

    If you prefer not to install the tool globally, you can use npx or pnpx to download and execute google-that in a single command.
    # Using npx
    npx google-that
    
    # Using pnpx
    pnpx google-that
  7. Install google-sr via npm, pnpm, or yarn

    Install the google-sr package using one of the following package manager commands to begin scraping Google search results.
    # Using npm
    npm i google-sr
    
    # Using pnpm
    pnpm add google-sr
    
    # Using yarn
    yarn add google-sr
  8. Install google-that CLI globally

    google-that is a CLI tool used to scrape Google search results without requiring an API key. To install it globally, use one of the following package managers. After installation, restart your terminal to ensure the google-that command is available in your path.
    # Using npm
    npm i -g google-that
    
    # Using pnpm
    pnpm add -g google-sr
    
    # Using yarn
    yarn add -g google-sr
  9. Perform multi-page searches with searchWithPages

    The searchWithPages function allows retrieving results from multiple pages. The pages option can be a single number (which retrieves all pages from 0 up to that number) or an array of specific page numbers to fetch.
    import { searchWithPages } from 'google-sr';
    
    // Fetch pages 0 through 5
    const searchResults = await searchWithPages({ query: 'nodejs', pages: 5 });
    
    // Fetch specific pages (does not need to be in order)
    await searchWithPages({
        query: 'nodejs',
        pages: [1, 2, 3, 4, 5]
    });
  10. Extract Google Current Time results

    Use these selectors to extract time-related information from 'current time' queries, including the location, the digital time, and the time expressed in words.
    {
        "location": "span.BNeawe.tAd8D.AP7Wnd > span.r0bn4c.rQMQod",
        "time": "div.BNeawe.iBp4i.AP7Wnd > div > div.BNeawe.iBp4i.AP7Wnd",
        "timeInWords": "div.BNeawe.tAd8D.AP7Wnd > div > div.BNeawe.tAd8D.AP7Wnd"
    }
  11. Extract Google Dictionary definition results

    Use these selectors to extract dictionary data from 'define' queries, including the word, its phonetic pronunciation, audio links, definitions, and usage examples.
    {
        "audio": "audio:first",
        "phonetic": "span > div.BNeawe.tAd8D.AP7Wnd",
        "word": "h3 > div.BNeawe.deIvCb.AP7Wnd",
        "examples": "div.v9i61e > div.BNeawe > span.r0bn4c.rQMQod",
        "definitions": "div.v9i61e > div.BNeawe.s3v9rd.AP7Wnd:not(:has(span.r0bn4c.rQMQod))"
    }
  12. Parse Google search results using google-sr-selectors

    The google-sr-selectors package provides a set of HTML selectors specifically for parsing Google search results. It is designed to be used with jQuery-like modules such as Cheerio.
    npm install google-sr-selectors