feat: add js_instructions parameter to ZenRowsScraper.scrape()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 07:56:35 -07:00
parent 9258402427
commit 78ba7d0d21

View File

@@ -1,3 +1,4 @@
import json
import time import time
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Optional from typing import Optional
@@ -23,6 +24,7 @@ class ZenRowsScraper:
wait: Optional[int] = None, wait: Optional[int] = None,
wait_for: Optional[str] = None, wait_for: Optional[str] = None,
premium_proxy: bool = False, premium_proxy: bool = False,
js_instructions: Optional[list] = None,
): ):
"""Scrape a URL using ZenRows scraping SDK. """Scrape a URL using ZenRows scraping SDK.
@@ -32,6 +34,7 @@ class ZenRowsScraper:
wait: milliseconds to wait after page load wait: milliseconds to wait after page load
wait_for: css selector to wait for wait_for: css selector to wait for
premium_proxy: use residential proxy (ZenRows premium_proxy=true) premium_proxy: use residential proxy (ZenRows premium_proxy=true)
js_instructions: list of ZenRows instruction dicts (evaluate, wait_for, click, etc.)
""" """
self.logger.debug(f"ZenRows scraping url: {url}...") self.logger.debug(f"ZenRows scraping url: {url}...")
params: dict = {} params: dict = {}
@@ -43,6 +46,8 @@ class ZenRowsScraper:
params["wait"] = str(wait) params["wait"] = str(wait)
if wait_for is not None: if wait_for is not None:
params["wait_for"] = wait_for params["wait_for"] = wait_for
if js_instructions is not None:
params["js_instructions"] = json.dumps(js_instructions)
start = time.monotonic() start = time.monotonic()
response = self.client.get(url, params=params) response = self.client.get(url, params=params)
elapsed_time = round((time.monotonic() - start) * 1000) elapsed_time = round((time.monotonic() - start) * 1000)