simplex 1.2.70__tar.gz → 1.2.72__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.
Potentially problematic release.
This version of simplex might be problematic. Click here for more details.
- {simplex-1.2.70 → simplex-1.2.72}/PKG-INFO +1 -1
- {simplex-1.2.70 → simplex-1.2.72}/setup.py +1 -1
- {simplex-1.2.70 → simplex-1.2.72}/simplex/simplex.py +201 -192
- {simplex-1.2.70 → simplex-1.2.72}/simplex.egg-info/PKG-INFO +1 -1
- {simplex-1.2.70 → simplex-1.2.72}/LICENSE +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/README.md +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/setup.cfg +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex/__init__.py +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex/cli.py +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex/deploy/__init__.py +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex/deploy/push.py +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex.egg-info/SOURCES.txt +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex.egg-info/dependency_links.txt +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex.egg-info/entry_points.txt +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex.egg-info/requires.txt +0 -0
- {simplex-1.2.70 → simplex-1.2.72}/simplex.egg-info/top_level.txt +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import requests
|
|
2
|
-
import atexit
|
|
3
1
|
from typing import Optional, Union
|
|
4
2
|
import os
|
|
5
3
|
import json
|
|
6
4
|
import warnings
|
|
7
|
-
|
|
5
|
+
import requests
|
|
6
|
+
import time
|
|
8
7
|
try:
|
|
9
8
|
from rebrowser_playwright.sync_api import sync_playwright
|
|
10
9
|
PLAYWRIGHT_AVAILABLE = True
|
|
@@ -77,7 +76,6 @@ class Simplex:
|
|
|
77
76
|
def __init__(self, api_key: str):
|
|
78
77
|
self.api_key = api_key
|
|
79
78
|
self.session_id = None
|
|
80
|
-
atexit.register(self.close_session)
|
|
81
79
|
if PLAYWRIGHT_AVAILABLE:
|
|
82
80
|
self.pw_browser = None
|
|
83
81
|
self.pw = None
|
|
@@ -171,19 +169,18 @@ class Simplex:
|
|
|
171
169
|
|
|
172
170
|
return self.session_id, livestream_url
|
|
173
171
|
|
|
174
|
-
def goto(self, url: str,
|
|
175
|
-
if not
|
|
172
|
+
def goto(self, url: str, override_fail_state: bool = False):
|
|
173
|
+
if not self.session_id:
|
|
176
174
|
raise ValueError(f"Must call create_session before calling action goto with url='{url}'")
|
|
177
175
|
|
|
178
176
|
if not url.startswith('http://') and not url.startswith('https://'):
|
|
179
177
|
url = 'https://' + url
|
|
180
178
|
|
|
181
|
-
data = {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
data['session_id'] = self.session_id
|
|
179
|
+
data = {
|
|
180
|
+
'url': url,
|
|
181
|
+
'session_id': self.session_id,
|
|
182
|
+
'override_fail_state': override_fail_state
|
|
183
|
+
}
|
|
187
184
|
|
|
188
185
|
response = requests.post(
|
|
189
186
|
f"{BASE_URL}/goto",
|
|
@@ -199,20 +196,43 @@ class Simplex:
|
|
|
199
196
|
return
|
|
200
197
|
else:
|
|
201
198
|
raise ValueError(f"Failed to goto url: {response.json()['error']}")
|
|
202
|
-
|
|
199
|
+
|
|
200
|
+
def enqueue_actions(self, actions: list):
|
|
201
|
+
if not self.session_id:
|
|
202
|
+
raise ValueError(f"Must call create_session before calling action enqueue_actions with actions={actions}")
|
|
203
|
+
|
|
204
|
+
data = {
|
|
205
|
+
'actions': json.dumps(actions),
|
|
206
|
+
'session_id': self.session_id,
|
|
207
|
+
}
|
|
203
208
|
|
|
204
|
-
|
|
209
|
+
response = requests.post(
|
|
210
|
+
f"{BASE_URL}/enqueue_actions",
|
|
211
|
+
headers={
|
|
212
|
+
'x-api-key': self.api_key
|
|
213
|
+
},
|
|
214
|
+
data=data
|
|
215
|
+
)
|
|
216
|
+
if 'succeeded' not in response.json():
|
|
217
|
+
raise ValueError(f"It looks like the enqueue_actions action failed to return a response. Did you set your api_key when creating the Simplex class?")
|
|
218
|
+
|
|
219
|
+
if response.json()['succeeded']:
|
|
220
|
+
return
|
|
221
|
+
else:
|
|
222
|
+
raise ValueError(f"Failed to enqueue actions: {response.json()['error']}")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def click(self, element_description: str, override_fail_state: bool = False):
|
|
205
226
|
if not element_description or not element_description.strip():
|
|
206
227
|
raise ValueError("element_description cannot be empty")
|
|
207
|
-
if not
|
|
228
|
+
if not self.session_id:
|
|
208
229
|
raise ValueError(f"Must call create_session before calling action click with element_description='{element_description}'")
|
|
209
230
|
|
|
210
|
-
data = {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
data['session_id'] = self.session_id
|
|
231
|
+
data = {
|
|
232
|
+
'element_description': element_description,
|
|
233
|
+
'session_id': self.session_id,
|
|
234
|
+
'override_fail_state': override_fail_state
|
|
235
|
+
}
|
|
216
236
|
|
|
217
237
|
response = requests.post(
|
|
218
238
|
f"{BASE_URL}/click",
|
|
@@ -228,19 +248,17 @@ class Simplex:
|
|
|
228
248
|
else:
|
|
229
249
|
raise ValueError(f"Failed to click element: {response.json()['error']}")
|
|
230
250
|
|
|
231
|
-
def select_dropdown_option(self, element_description: str,
|
|
251
|
+
def select_dropdown_option(self, element_description: str, override_fail_state: bool = False):
|
|
232
252
|
if not element_description or not element_description.strip():
|
|
233
253
|
raise ValueError("element_description cannot be empty")
|
|
234
|
-
if not
|
|
254
|
+
if not self.session_id:
|
|
235
255
|
raise ValueError(f"Must call create_session before calling action select_from_dropdown with element_description='{element_description}'")
|
|
236
256
|
|
|
237
|
-
data = {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
data['session_id'] = self.session_id
|
|
243
|
-
|
|
257
|
+
data = {
|
|
258
|
+
'element_description': element_description,
|
|
259
|
+
'session_id': self.session_id,
|
|
260
|
+
'override_fail_state': override_fail_state
|
|
261
|
+
}
|
|
244
262
|
|
|
245
263
|
response = requests.post(
|
|
246
264
|
f"{BASE_URL}/select_dropdown_option",
|
|
@@ -257,19 +275,17 @@ class Simplex:
|
|
|
257
275
|
else:
|
|
258
276
|
raise ValueError(f"Failed to select dropdown option: {response.json()['error']}")
|
|
259
277
|
|
|
260
|
-
|
|
261
|
-
def scroll_to_element(self, element_description: str, cdp_url: str = None):
|
|
278
|
+
def scroll_to_element(self, element_description: str, override_fail_state: bool = False):
|
|
262
279
|
if not element_description or not element_description.strip():
|
|
263
280
|
raise ValueError("element_description cannot be empty")
|
|
264
|
-
if not
|
|
281
|
+
if not self.session_id:
|
|
265
282
|
raise ValueError(f"Must call create_session before calling action scroll_to_element with element_description='{element_description}'")
|
|
266
283
|
|
|
267
|
-
data = {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
data['session_id'] = self.session_id
|
|
284
|
+
data = {
|
|
285
|
+
'element_description': element_description,
|
|
286
|
+
'session_id': self.session_id,
|
|
287
|
+
'override_fail_state': override_fail_state
|
|
288
|
+
}
|
|
273
289
|
|
|
274
290
|
response = requests.post(
|
|
275
291
|
f"{BASE_URL}/scroll_to_element",
|
|
@@ -285,21 +301,18 @@ class Simplex:
|
|
|
285
301
|
return
|
|
286
302
|
else:
|
|
287
303
|
raise ValueError(f"Failed to scroll element into view: {response.json()['error']}")
|
|
288
|
-
|
|
289
|
-
|
|
290
304
|
|
|
291
|
-
def hover(self, element_description: str,
|
|
305
|
+
def hover(self, element_description: str, override_fail_state: bool = False):
|
|
292
306
|
if not element_description or not element_description.strip():
|
|
293
307
|
raise ValueError("element_description cannot be empty")
|
|
294
|
-
if not
|
|
308
|
+
if not self.session_id:
|
|
295
309
|
raise ValueError(f"Must call create_session before calling action hover with element_description='{element_description}'")
|
|
296
310
|
|
|
297
|
-
data = {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
data['session_id'] = self.session_id
|
|
311
|
+
data = {
|
|
312
|
+
'element_description': element_description,
|
|
313
|
+
'session_id': self.session_id,
|
|
314
|
+
'override_fail_state': override_fail_state
|
|
315
|
+
}
|
|
303
316
|
|
|
304
317
|
response = requests.post(
|
|
305
318
|
f"{BASE_URL}/hover",
|
|
@@ -316,18 +329,17 @@ class Simplex:
|
|
|
316
329
|
else:
|
|
317
330
|
raise ValueError(f"Failed to hover: {response.json()['error']}")
|
|
318
331
|
|
|
319
|
-
def type(self, text: str,
|
|
332
|
+
def type(self, text: str, override_fail_state: bool = False):
|
|
320
333
|
if not text or not text.strip():
|
|
321
334
|
raise ValueError("text cannot be empty")
|
|
322
|
-
if not
|
|
335
|
+
if not self.session_id:
|
|
323
336
|
raise ValueError(f"Must call create_session before calling action type with text='{text}'")
|
|
324
337
|
|
|
325
|
-
data = {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
data['session_id'] = self.session_id
|
|
338
|
+
data = {
|
|
339
|
+
'text': text,
|
|
340
|
+
'session_id': self.session_id,
|
|
341
|
+
'override_fail_state': override_fail_state
|
|
342
|
+
}
|
|
331
343
|
|
|
332
344
|
response = requests.post(
|
|
333
345
|
f"{BASE_URL}/type",
|
|
@@ -339,19 +351,16 @@ class Simplex:
|
|
|
339
351
|
if response.json()['succeeded']:
|
|
340
352
|
return
|
|
341
353
|
else:
|
|
342
|
-
raise ValueError(f"Failed to type text: {response.json()['error']}")
|
|
343
|
-
|
|
354
|
+
raise ValueError(f"Failed to type text: {response.json()['error']}")
|
|
344
355
|
|
|
345
|
-
def reload(self,
|
|
346
|
-
if not
|
|
356
|
+
def reload(self, override_fail_state: bool = False):
|
|
357
|
+
if not self.session_id:
|
|
347
358
|
raise ValueError("Must call create_session before calling action reload")
|
|
348
359
|
|
|
349
|
-
data = {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
else:
|
|
354
|
-
data['session_id'] = self.session_id
|
|
360
|
+
data = {
|
|
361
|
+
'session_id': self.session_id,
|
|
362
|
+
'override_fail_state': override_fail_state
|
|
363
|
+
}
|
|
355
364
|
|
|
356
365
|
response = requests.post(
|
|
357
366
|
f"{BASE_URL}/reload",
|
|
@@ -367,16 +376,14 @@ class Simplex:
|
|
|
367
376
|
else:
|
|
368
377
|
raise ValueError(f"Failed to reload: {response.json()['error']}")
|
|
369
378
|
|
|
370
|
-
def press_enter(self,
|
|
371
|
-
if not
|
|
379
|
+
def press_enter(self, override_fail_state: bool = False):
|
|
380
|
+
if not self.session_id:
|
|
372
381
|
raise ValueError("Must call create_session before calling action press_enter")
|
|
373
382
|
|
|
374
|
-
data = {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
else:
|
|
379
|
-
data['session_id'] = self.session_id
|
|
383
|
+
data = {
|
|
384
|
+
'session_id': self.session_id,
|
|
385
|
+
'override_fail_state': override_fail_state
|
|
386
|
+
}
|
|
380
387
|
|
|
381
388
|
response = requests.post(
|
|
382
389
|
f"{BASE_URL}/press_enter",
|
|
@@ -392,16 +399,14 @@ class Simplex:
|
|
|
392
399
|
else:
|
|
393
400
|
raise ValueError(f"Failed to press enter: {response.json()['error']}")
|
|
394
401
|
|
|
395
|
-
def press_tab(self,
|
|
396
|
-
if not
|
|
402
|
+
def press_tab(self, override_fail_state: bool = False):
|
|
403
|
+
if not self.session_id:
|
|
397
404
|
raise ValueError("Must call create_session before calling action press_tab")
|
|
398
405
|
|
|
399
|
-
data = {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
else:
|
|
404
|
-
data['session_id'] = self.session_id
|
|
406
|
+
data = {
|
|
407
|
+
'session_id': self.session_id,
|
|
408
|
+
'override_fail_state': override_fail_state
|
|
409
|
+
}
|
|
405
410
|
|
|
406
411
|
response = requests.post(
|
|
407
412
|
f"{BASE_URL}/press_tab",
|
|
@@ -417,16 +422,14 @@ class Simplex:
|
|
|
417
422
|
else:
|
|
418
423
|
raise ValueError(f"Failed to press tab: {response.json()['error']}")
|
|
419
424
|
|
|
420
|
-
def delete_text(self,
|
|
421
|
-
if not
|
|
425
|
+
def delete_text(self, override_fail_state: bool = False):
|
|
426
|
+
if not self.session_id:
|
|
422
427
|
raise ValueError("Must call create_session before calling action delete_text")
|
|
423
428
|
|
|
424
|
-
data = {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
else:
|
|
429
|
-
data['session_id'] = self.session_id
|
|
429
|
+
data = {
|
|
430
|
+
'session_id': self.session_id,
|
|
431
|
+
'override_fail_state': override_fail_state
|
|
432
|
+
}
|
|
430
433
|
|
|
431
434
|
response = requests.post(
|
|
432
435
|
f"{BASE_URL}/delete_text",
|
|
@@ -442,45 +445,40 @@ class Simplex:
|
|
|
442
445
|
else:
|
|
443
446
|
raise ValueError(f"Failed to delete text: {response.json()['error']}")
|
|
444
447
|
|
|
445
|
-
def
|
|
446
|
-
if not
|
|
447
|
-
raise ValueError("
|
|
448
|
-
if not cdp_url and not self.session_id:
|
|
449
|
-
raise ValueError(f"Must call create_session before calling action extract_bbox with element_description='{element_description}'")
|
|
450
|
-
|
|
451
|
-
data = {'element_description': element_description}
|
|
448
|
+
def bot_tests(self, override_fail_state: bool = False):
|
|
449
|
+
if not self.session_id:
|
|
450
|
+
raise ValueError("Must call create_session before calling action bot_tests")
|
|
452
451
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
452
|
+
data = {
|
|
453
|
+
'session_id': self.session_id,
|
|
454
|
+
'override_fail_state': override_fail_state
|
|
455
|
+
}
|
|
457
456
|
|
|
458
|
-
response = requests.
|
|
459
|
-
f"{BASE_URL}/
|
|
457
|
+
response = requests.post(
|
|
458
|
+
f"{BASE_URL}/bot_tests",
|
|
460
459
|
headers={
|
|
461
460
|
'x-api-key': self.api_key
|
|
462
461
|
},
|
|
463
|
-
|
|
462
|
+
data=data
|
|
464
463
|
)
|
|
465
464
|
if 'succeeded' not in response.json():
|
|
466
|
-
raise ValueError(f"It looks like the
|
|
465
|
+
raise ValueError(f"It looks like the bot_tests action failed to return a response. Did you set your api_key when creating the Simplex class?")
|
|
467
466
|
if response.json()['succeeded']:
|
|
468
|
-
return
|
|
467
|
+
return
|
|
469
468
|
else:
|
|
470
|
-
raise ValueError(f"Failed to
|
|
469
|
+
raise ValueError(f"Failed to run bot tests: {response.json()['error']}")
|
|
471
470
|
|
|
472
|
-
def extract_text(self, element_description: str,
|
|
471
|
+
def extract_text(self, element_description: str, override_fail_state: bool = False):
|
|
473
472
|
if not element_description or not element_description.strip():
|
|
474
473
|
raise ValueError("element_description cannot be empty")
|
|
475
|
-
if not
|
|
474
|
+
if not self.session_id:
|
|
476
475
|
raise ValueError(f"Must call create_session before calling action extract_text with element_description='{element_description}'")
|
|
477
476
|
|
|
478
|
-
data = {
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
data['session_id'] = self.session_id
|
|
477
|
+
data = {
|
|
478
|
+
'element_description': element_description,
|
|
479
|
+
'session_id': self.session_id,
|
|
480
|
+
'override_fail_state': override_fail_state
|
|
481
|
+
}
|
|
484
482
|
|
|
485
483
|
response = requests.post(
|
|
486
484
|
f"{BASE_URL}/extract-text",
|
|
@@ -492,48 +490,20 @@ class Simplex:
|
|
|
492
490
|
response_json = response.json()
|
|
493
491
|
if 'succeeded' not in response_json:
|
|
494
492
|
raise ValueError(f"It looks like the extract_text action failed to return a response. Did you set your api_key when creating the Simplex class?")
|
|
495
|
-
if "succeeded"
|
|
493
|
+
if response_json["succeeded"]:
|
|
496
494
|
return response_json["text"]
|
|
497
495
|
else:
|
|
498
496
|
raise ValueError(f"Failed to extract text: {response_json['error']}")
|
|
499
497
|
|
|
500
|
-
def
|
|
501
|
-
if not
|
|
502
|
-
raise ValueError("element_description cannot be empty")
|
|
503
|
-
if not cdp_url and not self.session_id:
|
|
504
|
-
raise ValueError(f"Must call create_session before calling action extract_image with element_description='{element_description}'")
|
|
505
|
-
|
|
506
|
-
data = {'element_description': element_description}
|
|
507
|
-
|
|
508
|
-
if cdp_url:
|
|
509
|
-
data['cdp_url'] = cdp_url
|
|
510
|
-
else:
|
|
511
|
-
data['session_id'] = self.session_id
|
|
512
|
-
|
|
513
|
-
response = requests.get(
|
|
514
|
-
f"{BASE_URL}/extract-image",
|
|
515
|
-
headers={
|
|
516
|
-
'x-api-key': self.api_key
|
|
517
|
-
},
|
|
518
|
-
params=data
|
|
519
|
-
)
|
|
520
|
-
if 'succeeded' not in response.json():
|
|
521
|
-
raise ValueError(f"It looks like the extract_image action failed to return a response. Did you set your api_key when creating the Simplex class?")
|
|
522
|
-
if response.json()['succeeded']:
|
|
523
|
-
return response.json()["image"]
|
|
524
|
-
else:
|
|
525
|
-
raise ValueError(f"Failed to extract image: {response.json()['error']}")
|
|
526
|
-
|
|
527
|
-
def scroll(self, pixels: float, cdp_url: str = None):
|
|
528
|
-
if not cdp_url and not self.session_id:
|
|
498
|
+
def scroll(self, pixels: float, override_fail_state: bool = False):
|
|
499
|
+
if not self.session_id:
|
|
529
500
|
raise ValueError(f"Must call create_session before calling action scroll with pixels={pixels}")
|
|
530
501
|
|
|
531
|
-
data = {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
data['session_id'] = self.session_id
|
|
502
|
+
data = {
|
|
503
|
+
'pixels': pixels,
|
|
504
|
+
'session_id': self.session_id,
|
|
505
|
+
'override_fail_state': override_fail_state
|
|
506
|
+
}
|
|
537
507
|
|
|
538
508
|
response = requests.post(
|
|
539
509
|
f"{BASE_URL}/scroll",
|
|
@@ -549,17 +519,15 @@ class Simplex:
|
|
|
549
519
|
else:
|
|
550
520
|
raise ValueError(f"Failed to scroll: {response.json()['error']}")
|
|
551
521
|
|
|
552
|
-
def wait(self, milliseconds: int,
|
|
553
|
-
if not
|
|
522
|
+
def wait(self, milliseconds: int, override_fail_state: bool = False):
|
|
523
|
+
if not self.session_id:
|
|
554
524
|
raise ValueError(f"Must call create_session before calling action wait with milliseconds={milliseconds}")
|
|
555
525
|
|
|
556
|
-
data = {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
data['session_id'] = self.session_id
|
|
562
|
-
|
|
526
|
+
data = {
|
|
527
|
+
'milliseconds': milliseconds,
|
|
528
|
+
'session_id': self.session_id,
|
|
529
|
+
'override_fail_state': override_fail_state
|
|
530
|
+
}
|
|
563
531
|
response = requests.post(
|
|
564
532
|
f"{BASE_URL}/wait",
|
|
565
533
|
headers={
|
|
@@ -573,7 +541,7 @@ class Simplex:
|
|
|
573
541
|
return
|
|
574
542
|
else:
|
|
575
543
|
raise ValueError(f"Failed to wait: {response.json()['error']}")
|
|
576
|
-
|
|
544
|
+
|
|
577
545
|
def create_login_session(self, url: str, save_directory: Optional[str] = None):
|
|
578
546
|
if not PLAYWRIGHT_AVAILABLE:
|
|
579
547
|
raise ImportError("This feature requires playwright. Install simplex[playwright] to use it.")
|
|
@@ -669,17 +637,15 @@ class Simplex:
|
|
|
669
637
|
|
|
670
638
|
return filename
|
|
671
639
|
|
|
672
|
-
def get_network_response(self, url: str
|
|
640
|
+
def get_network_response(self, url: str):
|
|
673
641
|
print(f"Getting network response for {url}")
|
|
674
|
-
if not
|
|
642
|
+
if not self.session_id:
|
|
675
643
|
raise ValueError(f"Must call create_session before calling action get_network_response with url='{url}'")
|
|
676
644
|
|
|
677
|
-
data = {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
else:
|
|
682
|
-
data['session_id'] = self.session_id
|
|
645
|
+
data = {
|
|
646
|
+
'url': url,
|
|
647
|
+
'session_id': self.session_id
|
|
648
|
+
}
|
|
683
649
|
|
|
684
650
|
response = requests.post(
|
|
685
651
|
f"{BASE_URL}/get_network_response",
|
|
@@ -696,13 +662,12 @@ class Simplex:
|
|
|
696
662
|
else:
|
|
697
663
|
raise ValueError(f"Failed to get network response: {response.json()['error']}")
|
|
698
664
|
|
|
699
|
-
def restore_login_session(self, session_data: str
|
|
665
|
+
def restore_login_session(self, session_data: str):
|
|
700
666
|
"""
|
|
701
667
|
Restore a login session from either a file path or a JSON string.
|
|
702
668
|
|
|
703
669
|
Args:
|
|
704
670
|
session_data: Either a file path to JSON file or a JSON string
|
|
705
|
-
cdp_url: Optional CDP URL for remote debugging
|
|
706
671
|
"""
|
|
707
672
|
try:
|
|
708
673
|
# Try to parse as JSON string first
|
|
@@ -716,12 +681,9 @@ class Simplex:
|
|
|
716
681
|
raise ValueError(f"Failed to load session data. Input must be valid JSON string or path to JSON file. Error: {str(e)}")
|
|
717
682
|
|
|
718
683
|
data = {
|
|
719
|
-
'session_data': json.dumps(session_data_dict)
|
|
684
|
+
'session_data': json.dumps(session_data_dict),
|
|
685
|
+
'session_id': self.session_id
|
|
720
686
|
}
|
|
721
|
-
if cdp_url:
|
|
722
|
-
data['cdp_url'] = cdp_url
|
|
723
|
-
else:
|
|
724
|
-
data['session_id'] = self.session_id
|
|
725
687
|
|
|
726
688
|
response = requests.post(
|
|
727
689
|
f"{BASE_URL}/restore_login_session",
|
|
@@ -737,11 +699,12 @@ class Simplex:
|
|
|
737
699
|
else:
|
|
738
700
|
raise ValueError(f"Failed to restore login session: {response.json()['error']}")
|
|
739
701
|
|
|
740
|
-
def click_and_upload(self, element_description: str, file_path_or_callable: Union[str, callable]):
|
|
702
|
+
def click_and_upload(self, element_description: str, file_path_or_callable: Union[str, callable], override_fail_state: bool = False):
|
|
741
703
|
"""
|
|
742
704
|
Args:
|
|
743
705
|
element_description: Description of the element to click and upload to
|
|
744
706
|
file_path_or_callable: Either a path to the file to be uploaded or a callable that returns a file-like object in 'rb' mode
|
|
707
|
+
override_fail_state: Boolean to override fail state, default is False
|
|
745
708
|
"""
|
|
746
709
|
if not element_description or not element_description.strip():
|
|
747
710
|
raise ValueError("element_description cannot be empty")
|
|
@@ -763,7 +726,8 @@ class Simplex:
|
|
|
763
726
|
raise ValueError("You must provide either a valid file path or a callable that returns a file-like object.")
|
|
764
727
|
data = {
|
|
765
728
|
'element_description': element_description,
|
|
766
|
-
'session_id': self.session_id
|
|
729
|
+
'session_id': self.session_id,
|
|
730
|
+
'override_fail_state': override_fail_state
|
|
767
731
|
}
|
|
768
732
|
|
|
769
733
|
response = requests.post(
|
|
@@ -781,18 +745,18 @@ class Simplex:
|
|
|
781
745
|
else:
|
|
782
746
|
raise ValueError(f"Failed to click and upload: {response.json()['error']}")
|
|
783
747
|
|
|
784
|
-
def click_and_download(self, element_description: str):
|
|
748
|
+
def click_and_download(self, element_description: str, override_fail_state: bool = False):
|
|
785
749
|
if not element_description or not element_description.strip():
|
|
786
750
|
raise ValueError("element_description cannot be empty")
|
|
787
751
|
if not self.session_id:
|
|
788
752
|
raise ValueError(f"Must call create_session before calling action click_and_download with element_description='{element_description}'")
|
|
789
753
|
|
|
790
754
|
data = {
|
|
791
|
-
'element_description': element_description
|
|
755
|
+
'element_description': element_description,
|
|
756
|
+
'session_id': self.session_id,
|
|
757
|
+
'override_fail_state': override_fail_state
|
|
792
758
|
}
|
|
793
759
|
|
|
794
|
-
data['session_id'] = self.session_id
|
|
795
|
-
|
|
796
760
|
response = requests.post(
|
|
797
761
|
f"{BASE_URL}/click_and_download",
|
|
798
762
|
headers={
|
|
@@ -829,18 +793,17 @@ class Simplex:
|
|
|
829
793
|
|
|
830
794
|
return filename, response.content
|
|
831
795
|
|
|
832
|
-
def exists(self, element_description: str,
|
|
796
|
+
def exists(self, element_description: str, override_fail_state: bool = False):
|
|
833
797
|
if not element_description or not element_description.strip():
|
|
834
798
|
raise ValueError("element_description cannot be empty")
|
|
835
|
-
if not
|
|
799
|
+
if not self.session_id:
|
|
836
800
|
raise ValueError(f"Must call create_session before calling action exists with element_description='{element_description}'")
|
|
837
801
|
|
|
838
|
-
data = {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
data['session_id'] = self.session_id
|
|
802
|
+
data = {
|
|
803
|
+
'element_description': element_description,
|
|
804
|
+
'session_id': self.session_id,
|
|
805
|
+
'override_fail_state': override_fail_state
|
|
806
|
+
}
|
|
844
807
|
|
|
845
808
|
response = requests.post(
|
|
846
809
|
f"{BASE_URL}/exists",
|
|
@@ -856,4 +819,50 @@ class Simplex:
|
|
|
856
819
|
if response_json['succeeded']:
|
|
857
820
|
return response_json['exists'], response_json['reasoning']
|
|
858
821
|
else:
|
|
859
|
-
raise ValueError(f"Failed to check if element exists: {response_json['error']}")
|
|
822
|
+
raise ValueError(f"Failed to check if element exists: {response_json['error']}")
|
|
823
|
+
|
|
824
|
+
def capture_login_session(self, override_fail_state: bool = False):
|
|
825
|
+
data = {
|
|
826
|
+
'session_id': self.session_id,
|
|
827
|
+
'override_fail_state': override_fail_state
|
|
828
|
+
}
|
|
829
|
+
response = requests.post(
|
|
830
|
+
f"{BASE_URL}/capture_login_session",
|
|
831
|
+
headers={
|
|
832
|
+
'x-api-key': self.api_key
|
|
833
|
+
},
|
|
834
|
+
data=data
|
|
835
|
+
)
|
|
836
|
+
if 'succeeded' not in response.json():
|
|
837
|
+
raise ValueError(f"It looks like the capture_login_session action failed to return a response. Did you set your api_key when creating the Simplex class?")
|
|
838
|
+
response_json = response.json()
|
|
839
|
+
if "storage_state" in response_json:
|
|
840
|
+
print("response keys: ", response_json['storage_state'].keys())
|
|
841
|
+
# print(response_json)
|
|
842
|
+
if response_json['succeeded']:
|
|
843
|
+
return response_json['storage_state']
|
|
844
|
+
else:
|
|
845
|
+
raise ValueError(f"Failed to capture login session: {response_json['error']}")
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
def get_page_url(self, override_fail_state: bool = False):
|
|
849
|
+
data = {
|
|
850
|
+
'session_id': self.session_id,
|
|
851
|
+
'override_fail_state': override_fail_state
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
response = requests.post(
|
|
855
|
+
f"{BASE_URL}/get_page_url",
|
|
856
|
+
headers={
|
|
857
|
+
'x-api-key': self.api_key
|
|
858
|
+
},
|
|
859
|
+
data=data
|
|
860
|
+
)
|
|
861
|
+
if 'succeeded' not in response.json():
|
|
862
|
+
raise ValueError(f"It looks like the get_page_url action failed to return a response. Did you set your api_key when creating the Simplex class?")
|
|
863
|
+
response_json = response.json()
|
|
864
|
+
# print(response_json)
|
|
865
|
+
if response_json['succeeded']:
|
|
866
|
+
return response_json['url']
|
|
867
|
+
else:
|
|
868
|
+
raise ValueError(f"Failed to get page url: {response_json['error']}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|