phantomfetch 0.5.2__tar.gz → 0.5.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: phantomfetch
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: High-performance agentic web scraping library combining curl-cffi speed with Playwright browser capabilities
5
5
  Keywords: web-scraping,playwright,curl-cffi,async,browser-automation,http-client,agentic,anti-detection
6
6
  Author: CosmicBull
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "phantomfetch"
3
- version = "0.5.2"
3
+ version = "0.5.4"
4
4
  description = "High-performance agentic web scraping library combining curl-cffi speed with Playwright browser capabilities"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -274,6 +274,9 @@ async def execute_actions(
274
274
  else throw new Error(`Extract target not found: ${act.selector}`);
275
275
  } else if (act.action === 'evaluate') {
276
276
  if (act.value) actionResult.data = eval(act.value);
277
+ } else {
278
+ // Actions not handled in JS (screenshot, etc.) — defer to Python
279
+ actionResult.data = "__DEFERRED_TO_PYTHON__";
277
280
  }
278
281
  } catch (err) {
279
282
  actionResult.success = false;
@@ -300,6 +303,40 @@ async def execute_actions(
300
303
  "limit": limit,
301
304
  },
302
305
  )
306
+
307
+ # Process deferred actions (screenshot, etc.) via Python Playwright
308
+ page_for_deferred = (
309
+ page if isinstance(page, Page) else page.page
310
+ )
311
+ for iter_result in loop_results:
312
+ for ar in iter_result.get("results", []):
313
+ if ar.get("data") == "__DEFERRED_TO_PYTHON__":
314
+ deferred_action = ar.get("action")
315
+ if (
316
+ deferred_action
317
+ and deferred_action.get("action")
318
+ == "screenshot"
319
+ ):
320
+ try:
321
+ path = (
322
+ str(
323
+ deferred_action.get("value")
324
+ )
325
+ if deferred_action.get("value")
326
+ else None
327
+ )
328
+ kwargs = {}
329
+ if deferred_action.get("full_page"):
330
+ kwargs["full_page"] = True
331
+ img_bytes = await page_for_deferred.screenshot(
332
+ path=path, **kwargs
333
+ )
334
+ ar["data"] = img_bytes
335
+ ar["success"] = True
336
+ except Exception as e:
337
+ ar["success"] = False
338
+ ar["error"] = str(e)
339
+
303
340
  result.data = loop_results
304
341
  except Exception as e:
305
342
  result.success = False
@@ -581,8 +618,7 @@ async def execute_actions(
581
618
  kwargs[k] = v
582
619
 
583
620
  img_bytes = await screenshot_ctx.screenshot(path=path, **kwargs)
584
- if not path:
585
- result.data = img_bytes
621
+ result.data = img_bytes
586
622
 
587
623
  case "wait_for_load":
588
624
  target_page = ctx if isinstance(ctx, Page) else ctx.page
File without changes