facundoolano / google-play-scraper

Node.js scraper to get data from Google Play
MIT License
2.32k stars 629 forks source link

TypeError: Cannot read properties of undefined (reading 'map') when using .search() #613

Open bulgarian-beast opened 1 year ago

bulgarian-beast commented 1 year ago

This issue have been tested on the official node Dockerfile, and a MacOS.

Description:

Got a TypeError: Cannot read properties of undefined (reading 'map') when using .search()

Example Dockerfile:

FROM node

EXPOSE 3000

WORKDIR /app

COPY . .

RUN npm install

CMD node server.js

Example code:

const gplay = require('google-play-scraper');

gplay.search(
  {
    term: 'social',
    lang: 'fr',
    country: 'FR',
    num: 5
  }
  )
  .then((apps) => { console.log(apps) })
  .catch((error) => {
    console.log(error);
  });

Error message:

TypeError: Cannot read properties of undefined (reading 'map')
    at node_modules/ramda/dist/ramda.js:578:31
    at Object.f2 [as map] (node_modules/ramda/dist/ramda.js:473:22)
    at processFirstPage (node_modules/google-play-scraper/lib/search.js:101:27)
    at node_modules/google-play-scraper/lib/search.js:31:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
bulgarian-beast commented 1 year ago

It looks like it's related to: country: 'FR', because when I put: country: 'US', it works.

Hoping it will help.

degola commented 1 year ago

I have the same issue with this request and it seems to be a language issue but we'd love to scrape different languages:

const gplay = require('google-play-scraper')
await gplay.search({
  term: 'escacs',
  country: 'es',
  lang: 'ca',
  num: 200,
  fullDetail: true
})

There seems to be something wrong with the parsing in search.js:101, so far I came to the point that moreResultsSection is undefined/null in line https://github.com/facundoolano/google-play-scraper/blob/main/lib/search.js#L98.

I'm not familiar with Ramda and how its supposed to work to find a corresponding patch quickly, maybe someone else has an idea?

degola commented 1 year ago

The unit tests fail on search as well, it looks like the parsing breaks especially if/when there are less than 30 apps for a search result.

KaKi87 commented 1 year ago

A playsearch.kaki87.net user discovered that failing single-word queries may be fixed by adding quotes, possibly due to the following layout change they captured :

netgear "netgear"

when I put: country: 'US', it works.

Not universal, unfortunately.

For example, when term = netgear, then US won't work, while FR & ES do.

degola commented 1 year ago

Interesting, that seems to work indeed, just putting the term in quotes ' seems to work for all countries (at least not yet found a keyword which doesn't work). Probably just a temporarily solution but better than nothing :-).

KaKi87 commented 1 year ago

Well, it only works when searching apps by title, it won't work with generic terms like "web browser" for example.

jbigman commented 1 year ago

I checked both

await gplay.search({
  term: 'escacs',
  country: 'es',
  lang: 'ca',
  num: 200,
  fullDetail: true
})

await gplay.search({
  term: 'social',
  lang: 'fr',
  country: 'FR',
  num: 5
})

Seems to be corrected with last merged PRs

samandmaxphoto commented 5 months ago

I think I have a similar or related issue. I isolated it to a single keyword that doesn't appear to work.

If I try this request with v10.0.0 of the library :

import gplay from "google-play-scraper";

gplay.search({
    term: 'Viulunvirittäjä',
}).then(r => {
    console.log(r)
})

Then I get this error :

file:///blabla/node_modules/ramda/es/internal/_dispatchable.js:31
        if (typeof obj[methodNames[idx]] === 'function') {
                      ^

TypeError: Cannot read properties of undefined (reading 'fantasy-land/map')
    at file:///blabla/node_modules/ramda/es/internal/_dispatchable.js:31:23
    at Module.f2 (file:///blabla/node_modules/ramda/es/internal/_curry2.js:28:14)
    at processFirstPage (file:///blabla/node_modules/google-play-scraper/lib/search.js:99:27)
    at file://blabla/node_modules/google-play-scraper/lib/search.js:29:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.10.0

I tried a bunch of options (notably in terms of country and language but also throttling, number of results etc...) and nothing worked. Funnily enough searching for "Viulun virittäjä" does work perfectly.

I also tried the quote trick from above to no avail.

I'm wondering if this could be due to the play store returning zero result for that specific request (see here : https://play.google.com/store/search?q=Viulunviritt%C3%A4j%C3%A4&c=apps ), so I wanted to try finding another request with no result but I couldn't find a single one. Even entering a bunch of gibberish the Play Store would still give me some result.

The issue is that it's completely breaking the script I'm using, and I haven't managed to work around it apart from finding the bad keyword and specifically excluding it from my script. Any help?