Use ProxyGenerator to avoid Google Scholar blocking
mainTo avoid being blocked by Google Scholar, use the ProxyGenerator class to manage connections. You must initialize a ProxyGenerator object, select a connection method, and then pass that object to scholarly.use_proxy().
Important: Create a new ProxyGenerator object whenever you change the proxy method to avoid unexpected behavior.
Proxy Selection Methods:
ScraperAPI(api_key, ...)Luminati(usr, passwd, port, ...)FreeProxies()SingleProxy(http, https)Tor_Internal(tor_cmd, ...)(Deprecated since v1.5)Tor_External(tor_sock_port, tor_control_port, tor_password)(Deprecated since v1.5)
Proxy Usage Modes:
- Smart Mode (Default):
scholarly.use_proxy(pg)—scholarlyuses the proxy only for requests that might be blocked, otherwise it usesFreeProxies. - Full Proxy Mode:
scholarly.use_proxy(pg, pg)— All requests are routed through your specified proxy.
from scholarly import ProxyGenerator
import scholarly
pg = ProxyGenerator()
# Select a method (e.g., SingleProxy)
success = pg.SingleProxy(http='<your http proxy>', https='<your https proxy>')
if success:
scholarly.use_proxy(pg)
# Perform scholarly actions
author = next(scholarly.search_author('Steven A Cholewiak'))
scholarly.pprint(author)