google-this

repository·main·Indexed 18 days ago

https://github.com/luanrt/google-this

A Node.js module for retrieving organic search results and structured data from Google. It provides functionality to extract knowledge panels, featured snippets, 'people also ask' questions, and specialized data for translations, dictionaries, and song lyrics. The library supports standard web searches via google.search(), image searches via google.image(), reverse image searches using file buffers, and top news retrieval via getTopNews().

Tokens
5.9K
Snippets
18
Records
26
Agent score
63%

What's inside googlethis

  1. Retrieve Knowledge Graph, Translation, and Dictionary data

    main

    The library can parse various specialized Google search results by using specific query patterns. When a search matches a known pattern, the corresponding field is populated in the response object.

    Supported Patterns:

    • Knowledge Graph: Search for entities (e.g., people, places, things).
    • Google Translate: Use patterns like "translate [text] to [language]".
    • Google Dictionary: Use patterns like "define [word]".
    • Song Lyrics: Use patterns like "[song name] song lyrics".
  2. Understand the search response structure

    main

    The response from google.search() is a JSON object containing several key sections:

    • results: An array of organic search result objects. Each object includes title, description, url, is_sponsored, and favicons (high_res and low_res).
    • knowledge_panel: Data regarding the entity searched, including type, title, description, metadata (key-value pairs), ratings, and images.
    • people_also_ask: An array of strings containing common questions related to the search query.
    • featured_snippet: Information about the featured snippet if available.
    • videos, top_stories, weather, time, location, dictionary, translation, unit_converter: Other specialized Google data sections (may be empty or null depending on the query).
  3. The KnowledgeGraph data structure

    main

    The KnowledgeGraph class is a data structure used to represent the information extracted from a Google Knowledge Panel. It organizes various types of entities (like people, movies, books, or songs) into a structured format.

    When an instance is constructed with a data object and a jQuery-like selector object ($), it populates the following fields based on the available information in the panel:

    • type: The category of the knowledge panel (e.g., 'Person', 'Movie').
    • title: The main heading of the panel.
    • description: The summary text provided.
    • url: The primary URL associated with the entity.
    • metadata: An array of MetadataItem objects containing { title, value } pairs.
    • books: An array of { title, year } objects.
    • tv_shows_and_movies: An array of { title, year } objects.
    • ratings: An array of rating objects (e.g., { name: 'Google Users', rating: '4.5' }).
    • available_on: An array of strings representing platforms where content is available.
    • images: An array of { url, source } objects.
    • songs: An array of { title, album } objects.
    • socials: An array of Social objects containing { name, url, icon }.
    • demonstration: A URL to a video demonstration (if available).
    • lyrics: A string containing the song lyrics (if available).
  4. Configure search options for google.search()

    main

    The options object passed to google.search() allows you to customize the search request:

    • page: (number) The page number to retrieve (starting from 0).
    • safe: (boolean) Enables or disables Safe Search.
    • parse_ads: (boolean) If set to true, sponsored results (ads) will be parsed into the results.
    • additional_params: (object) An object containing additional Google search parameters (e.g., hl for language).
  5. Perform a Reverse Image Search

    main

    The google-this library supports reverse image searching. When performing a reverse image search, the API returns an array of objects representing matching web pages. Each object contains the title, a description (which often includes image dimensions and snippets), and the source url.

    [
       {
          "title":"Guess I'll Just Die | Meme Generator",
          "description":"401 × 401 · Oct 1, 2016 — Create your own images with the Guess I'll Just Die meme generator.",
          "url":"https://memegenerator.net/Guess-ILl-Just-Die"
       },
       {
          "title":"I Guess I Ll Just Die - Love Meme",
          "description":"401 × 401 · Apr 23, 2020 — 4 6k points 1 year ago. Upload your own image. Guess i ll die meme generator the fastest meme generator on the planet. A stock photo of a white ...",
          "url":"https://lovememepic.blogspot.com/2020/04/i-guess-i-ll-just-die.html"
       }
    ]
  6. Perform an image search with google.image()

    main

    Use the google.image(query, options) method to search for images based on a text query. You can pass an options object to configure the search, such as setting safe: false to disable safe search filtering.

    import google from 'googlethis';
    
    // Image Search
    const images = await google.image('The Wolf Among Us', { safe: false });
    console.log(images);
  7. Perform a Google search with google.search()

    main

    Use the google.search(query, options) method to retrieve organic search results. The method is asynchronous and returns a response object containing search results, knowledge panels, and other Google-specific data.

    import google from 'googlethis';
    
    const options = {
      page: 0, 
      safe: false, // Safe Search
      parse_ads: false, // If set to true sponsored results will be parsed
      additional_params: {
        // add additional parameters here
        hl: 'en' 
      }
    };
      
    const response = await google.search('TWDG', options);
    console.log(response);
  8. Perform a reverse image search with google.search()

    main

    To perform a reverse image search, use the google.search(imageBuffer, options) method. Pass a buffer of the image file and set the ris (Reverse Image Search) option to true in the options object. The results are accessible via the results property on the returned object.

    import google from 'googlethis';
    import fs from 'fs';
    
    // Reverse Image Search
    const my_awesome_image = fs.readFileSync('./wow.png');
    const reverse = await google.search(my_awesome_image, { ris: true });
    
    console.log(reverse.results);
  9. Data format for Google Dictionary results

    main

    When using definition queries, the dictionary field is returned containing phonetic information, audio links, definitions, and usage examples.

    {
       "dictionary":{
          "word":"a·maz·ing",
          "phonetic":"/əˈmāziNG/",
          "audio":"https://ssl.gstatic.com/dictionary/static/sounds/20200429/amazing--_us_1.mp3",
          "definitions":[
             "causing great surprise or wonder; astonishing.",
             "startlingly impressive."
          ],
          "examples":[
             "\"an amazing number of people registered\"",
             "\"she makes the most amazing cakes\""
          ]
       }
    }
  10. Data format for Google Translate results

    main

    When using translation queries, the translation field is returned containing the source and target language details and the translated text.

    {
       "translation": {
          "source_language":"English - detected",
          "target_language":"German",
          "source_text":"this is a test",
          "target_text":"das ist ein Test"
       }
    }
  11. Image Search Result Data Format

    main

    When performing an image search, the API returns an array of image objects. Each object contains metadata about the image, its dimensions, a color representation, a preview URL, and the source information (origin).

    [
        {
            "id": "cn9_VEKgPl1w1M",
            "url": "https://static.gamespot.com/uploads/original/416/4161502/2309313-wolf among us 360 - wolf among us - 2013-10-07 08-32-1309.jpg",
            "width": 1080,
            "height": 1920,
            "color": "rgb(19,32,13)",
            "preview": {
                "url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSQuS0Jm-w_QvTPXIrZqmUccBdogAEixxgXSA&usqp=CAU",
                "width": 168,
                "height": 300
            },
            "origin": {
                "title": "The Wolf Among Us: Episode 1 - Faith ...",
                "website": {
                    "name": "gamespot.com",
                    "domain": "GameSpot",
                    "url": "https://www.gamespot.com/reviews/the-wolf-among-us-episode-1-faith-review/1900-6415466/"
                }
            }
        }
    ]