scholar-package: scholar

scholar-packageR Documentation

scholar

Description

The scholar package provides functions to extract citation data from Google Scholar. There are also convenience functions for comparing multiple scholars and predicting h-index scores based on past publication records.

Google Scholar cookies

Google does not encourage people to use the scholar website as an API. You will find a number of issues related to this if you follow: https://github.com/jkeirstead/scholar/issues?q=is:issue+cookie

If you try to fetch too many pages, you can expect to see your access to scholar blocked. One step that they do take is to provide a session cookie. Reusing these seems to help. If you wish to write your own code to interact with Google Scholar, we recommend that you use the get_scholar_resp function to carry out the query.

Some endpoints, author search and the cited-by list among them, now want a session that only a browser has. set_scholar_cookie hands that session to the package: either paste the Cookie value of a browser that can open the page, or point it at a file exported from one. Prefer the file, and read it from an environment variable rather than writing it into a script, because a session is a credential and an option value ends up in the command history. The cookies that matter, NID, _Secure-ENID, GSP and SOCS, are HttpOnly, so a browser will not reveal them to a script or a copy button: take them from the developer tools under Application, or with an extension that exports a cookie file. Google publishes their lifetimes as six months for NID and thirteen for _Secure-ENID and SOCS, counted from last use, and ends a session sooner when it looks automated, so expect to export it again.

The session is sent as a cookie rather than as a header of that name, so it is merged with what Google sets on the connection and is not dropped when a request is redirected to a sign-in host. It is sent only to a Google host: a mirror that is not Google's is refused the session and told so, because handing a Google credential to somebody else's server is not something a package should do quietly.

None of this is a sanctioned API. Scholar has no API and no OAuth scope, and Google's terms forbid automated access in ways its machine-readable instructions disallow; reusing your own session is personal use, not a distribution channel, and it puts that account's Google access at risk of a challenge or suspension. Use a dedicated account if you must, keep the session out of logs and version control, and for anything at scale use OpenAlex (https://api.openalex.org), which is meant for this and needs no session at all.

Requests are refused, rate limited or redirected

Google Scholar has no public API and guards the website against automated clients, so a request can fail for reasons that have nothing to do with the ID you passed. The package sends browser-like headers on every request and backs off before retrying, but three outcomes are still worth recognising:

  • HTTP 403 on the search pages. Scholar rejects a client whose User-Agent names a library, which is why the same query works in a browser and not in a script.

  • A redirect to a sign-in or captcha page, reported as Google Scholar redirected to a Google sign-in page or answered with its captcha page. Some endpoints, author search among them, now sit behind a Google login, and a shared or data-centre IP (a hosted shiny app, a CI runner) is challenged more often than a workstation. These requests are not retried, because retrying cannot change the answer.

  • HTTP 429, meaning this IP has asked too often. The package waits, using the Retry-After header when Scholar supplies it and otherwise an exponentially growing delay, and gives up with a warning when Google asks for longer than the budget allows.

When a function returns NA or an empty table, read the warning: it names the reason. To keep Scholar happy, request less (set scholar_request_delay), fetch from a residential connection, or point the package at a mirror with set_scholar_mirror.

Configuration

the following options are read on every request, and each falls back to the environment variable of the same name in upper case, which is what to set on a server or in CI.

  • scholar_site: base URL of Google Scholar or a compatible mirror, see set_scholar_mirror.

  • scholar_user_agent (SCHOLAR_USER_AGENT): the User-Agent sent. Defaults to a desktop Chrome string.

  • scholar_accept_language (SCHOLAR_ACCEPT_LANGUAGE): sent as Accept-Language. Defaults to en-US,en;q=0.9; Scholar serves different markup per language, so change it only if you know why.

  • scholar_request_delay (SCHOLAR_REQUEST_DELAY): seconds to wait before every request. Default 0. Set this in loops over many publications, where one profile fetch follows another.

  • scholar_retry_delay and scholar_retry_max_delay: the first wait and the ceiling for the exponentially growing wait before a retry. Defaults to 1 and 30 seconds.

  • scholar_retry_budget (SCHOLAR_RETRY_BUDGET): how many seconds one process may spend waiting for Scholar in total, across every request. Default 60. Past that a rate-limited request is abandoned at once, since a CI job that keeps hammering a refusing server only extends its own lockout. Reset it with options(scholar_wait_used = 0).

  • scholar_cookie (SCHOLAR_COOKIE) and scholar_cookie_file (SCHOLAR_COOKIE_FILE): the session to present, see set_scholar_cookie. Entries from the option win over entries of the same name in the file. Prefer the environment variable, since an option value can end up in the command history.

  • scholar_openalex_mailto (SCHOLAR_OPENALEX_MAILTO): an address to identify yourself with when querying OpenAlex, which routes the request to their polite pool.

  • scholar_timeout (SCHOLAR_TIMEOUT): seconds a single request may take before it is abandoned. Default 30.

  • scholar_degraded: set to FALSE to stop the notice that author search is being refused by Google, which otherwise appears once per session.

  • scholar_call_home and scholar_handle: whether to seed a session, and the handle holding its cookies. Both are managed for you.

Author(s)

Maintainer: Guangchuang Yu guangchuangyu@gmail.com (ORCID)

Authors:

Other contributors:

Source

The package reads data from https://scholar.google.com. Dates and citation counts are estimated and are determined automatically by a computer program. Use at your own risk.

See Also

Useful links:


scholar documentation built on Oct. 29, 2026, 9:08 a.m.