LuanRT / google-this

A simple yet powerful module to retrieve organic search results and much more from Google.
https://www.npmjs.com/package/googlethis
MIT License
323 stars 77 forks source link

Move to Google's private API (Image Search) #22

Closed LuanRT closed 2 years ago

LuanRT commented 2 years ago

It seems like the google website uses an API to fetch image search results, the data is a bit messy but it's way faster than parsing raw html, has more metadata, returns up to 100 images, and allows more request options.

Sample Code

This could be done by sending a post request to https://www.google.com/_/VisualFrontendUi/data/batchexecute with the following payload (form data):

"f.req" => [
    [
      [
        "HoAMBc",
        JSON.stringify([
          null, null, [
            2,null,529,5,396,
            [],[9429,9520],[194,194],
            false,null,null,9520
          ],
          null,null,null,null, null,null,null,null,
          null,null,null,null, null,null,null,null,
          null,null,null,null, null,null,null,null,
          null,[
            "query-goes-here",
            null,null,null, null,null,null,
            null,null,null, null,null,null,
            null,null,null, null,null,null,
            null,null, "lnms"
          ],
          null,null,null,
          null,null,null,
          null,null,[
            null, "CAE=", "GGwgAA==" // these are protobufs
          ],null,true
        ]),
        null, "generic"
      ]
    ]
]
"at" => `ABrGKkThP-sNRUU6e86GjhgSvs0k:${new Date().getTime()}` // random request id + timestamp