Skip to content

Commit 4d49952

Browse files
committed
Skip checking test url with ScraperAPI
1 parent 31fa5f9 commit 4d49952

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

scholarly/_proxy_generator.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,17 @@ def _use_proxy(self, http: str, https: str = None) -> bool:
185185
https = http
186186

187187
proxies = {'http': http, 'https': https}
188-
self._proxy_works = self._check_proxy(proxies)
188+
if self.proxy_mode == ProxyMode.SCRAPERAPI:
189+
r = requests.get("http://api.scraperapi.com/account", params={'api_key': self._API_KEY}).json()
190+
if "error" in r:
191+
self.logger.warning(r["error"])
192+
self._proxy_works = False
193+
else:
194+
self._proxy_works = r["requestCount"] < int(r["requestLimit"])
195+
self.logger.info("Successful ScraperAPI requests %d / %d",
196+
r["requestCount"], r["requestLimit"])
197+
else:
198+
self._proxy_works = self._check_proxy(proxies)
189199

190200
if self._proxy_works:
191201
self._session.proxies = proxies
@@ -562,6 +572,9 @@ def ScraperAPI(self, API_KEY, country_code=None, premium=False, render=False):
562572
self.logger.warning(r["error"])
563573
return False
564574

575+
self._API_KEY = API_KEY
576+
self.proxy_mode = ProxyMode.SCRAPERAPI
577+
565578
r["requestLimit"] = int(r["requestLimit"])
566579
self.logger.info("Successful ScraperAPI requests %d / %d",
567580
r["requestCount"], r["requestLimit"])
@@ -586,7 +599,6 @@ def ScraperAPI(self, API_KEY, country_code=None, premium=False, render=False):
586599
proxy_works = self._use_proxy(http=f'{prefix}:{API_KEY}@proxy-server.scraperapi.com:8001')
587600
if proxy_works:
588601
self.logger.info("ScraperAPI proxy setup successfully")
589-
self.proxy_mode = ProxyMode.SCRAPERAPI
590602
self._session.verify = False
591603
return proxy_works
592604

0 commit comments

Comments
 (0)