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

Add an example of paginated searches #6

Open
ilyazub opened this issue Jun 1, 2021 · 0 comments
Open

Add an example of paginated searches #6

ilyazub opened this issue Jun 1, 2021 · 0 comments

Comments

@ilyazub
Copy link

ilyazub commented Jun 1, 2021

There is no documentation for paginated searches. For example, the Python wrapper has such documentation.

Pagination can be done like this:

// Try it online: https://replit.com/@serpapi/scrape-google-organic-results-urls-nodejs-serpapi

const SerpApi = require("google-search-results-nodejs");
const search = new SerpApi.GoogleSearch(process.env["API_KEY"]);

const params = {
  q: "watch movies online free",
  location: "Austin, TX",
};

function paginationCallback(result) {
  console.log(`\nCurrent page: ${result.serpapi_pagination.current}\n`);

  for (organicResult of result.organic_results) {
    console.log(organicResult.link);
  }

  const num = params.num || 10;

  search.json(
    {
      ...params,
      start: result.serpapi_pagination.current * num,
    },
    paginationCallback
  );
}

search.json(params, paginationCallback);

Sample output

Current page: 1

https://www.popcornflix.com/
https://tubitv.com/home
https://www.vudu.com/content/movies/uxpage/View-All-Free-Movies-TV/207
https://editorial.rottentomatoes.com/article/fresh-movies-you-can-watch-for-free-online-right-now/
https://www.netflix.com/
https://www.peacocktv.com/stream/movies
https://www.openculture.com/freemoviesonline
https://www.hulu.com/hub/movies
https://www.crackle.com/movies

Current page: 2

https://www.hotstar.com/us/movies
https://www.androidauthority.com/free-movies-online-streaming-1099293/
https://troypoint.com/free-online-movie-streaming-sites/
https://higherlogicdownload.s3.amazonaws.com/AMERICANBAR/UploadedImages/81986f90-2bb9-4235-8fc5-ded4d2894ca1/f9-fast-and-furious-9-niwq.pdf
https://www.komando.com/tv-streaming-reviews/best-sites-to-watch-movies-for-free/604808/
https://filmzie.com/
https://www.ctv.ca/movies
https://created.crayola.com/network/members/profile?UserKey=18eb5f43-080b-4c84-b8f1-f0870ca7dfec
https://www.fossmint.com/watch-free-movies-and-tv-shows-online/
https://vimeo.com/channels/1398936/videos/page:2

Also some search.pagination() wrapper can be added like for Python: serpapi/google-search-results-python#19.

@jvmvik @hartator What do you think?

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

1 participant