Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get multiple results? #6

Open
gajus opened this issue Feb 27, 2017 · 1 comment
Open

How to get multiple results? #6

gajus opened this issue Feb 27, 2017 · 1 comment

Comments

@gajus
Copy link

gajus commented Feb 27, 2017

The callback is called for each response.

To answer my own question,

const searchGoogle = (query: string, limit: number = 10) => {
  return new Promise((resolve, reject) => {
    const results = [];

    GoogleSearchScraper.search({
      host: 'www.google.com',
      lang: 'en',
      limit,
      query: query + ' site:imdb.com/title/'
    }, (error, result) => {
      if (error) {
        reject(error);
      } else {
        results.push(result);

        if (limit === results.length) {
          resolve(results);
        }
      }
    });
  });
};

However, this will hang if there are no results for the query.

Am I overlooking something?

@thibauts
Copy link
Owner

You're right, another callback should be fired when there are no more results. I'll accept PRs fixing this as long as they are backwards-compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants