kmisc 2.1.119__py3-none-any.whl → 2.1.121__py3-none-any.whl
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.
- kmisc/__init__.py +109 -0
- {kmisc-2.1.119.dist-info → kmisc-2.1.121.dist-info}/METADATA +1 -1
- kmisc-2.1.121.dist-info/RECORD +6 -0
- kmisc-2.1.119.dist-info/RECORD +0 -6
- {kmisc-2.1.119.dist-info → kmisc-2.1.121.dist-info}/LICENSE +0 -0
- {kmisc-2.1.119.dist-info → kmisc-2.1.121.dist-info}/WHEEL +0 -0
- {kmisc-2.1.119.dist-info → kmisc-2.1.121.dist-info}/top_level.txt +0 -0
kmisc/__init__.py
CHANGED
@@ -3447,6 +3447,115 @@ def Upper(src,default='org'):
|
|
3447
3447
|
if isinstance(src,str): return src.upper()
|
3448
3448
|
if default in ['org',{'org'}]: return src
|
3449
3449
|
return default
|
3450
|
+
|
3451
|
+
def web_capture(url,output_file,image_size='1920,1080',wait_time=3,ignore_certificate_error=False,username=None,password=None,auth_fields={'auth':{'type':'name','name':('username','password')},'submit':{'type':'submit','name':None}},next_do={}):
|
3452
|
+
#auth_fields.submit.type : name : login button with name
|
3453
|
+
# : id : login button with id
|
3454
|
+
# : submit : submit button without name or id
|
3455
|
+
#auth_fields.submit.name : <string>: name or id's submit name string
|
3456
|
+
#auth_fields.auth.type : name : username/password with name field
|
3457
|
+
# : id : username/password with name id
|
3458
|
+
#auth_fields.auth.name : (usernane,password) : username/password field string for name or id
|
3459
|
+
#next_do : put data and click submit
|
3460
|
+
|
3461
|
+
if isinstance(image_size,str):
|
3462
|
+
if 'x' in image_size:
|
3463
|
+
image_size=image_size.split('x')
|
3464
|
+
elif ',' in image_size:
|
3465
|
+
image_size=image_size.split(',')
|
3466
|
+
if isinstance(image_size,(list,tuple)) and len(image_size) == 2:
|
3467
|
+
image_size=','.join([str(i) for i in image_size])
|
3468
|
+
else:
|
3469
|
+
#Set it to default image size
|
3470
|
+
image_size='1920,1080'
|
3471
|
+
|
3472
|
+
if Import('import selenium'):
|
3473
|
+
return False,'Can not install selenium package'
|
3474
|
+
else:
|
3475
|
+
# Configure Chrome options for headless mode
|
3476
|
+
from selenium.webdriver.chrome.options import Options
|
3477
|
+
from selenium.webdriver.common.by import By
|
3478
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
3479
|
+
from selenium.webdriver.support import expected_conditions as EC
|
3480
|
+
chrome_options = Options()
|
3481
|
+
chrome_options.add_argument('--headless') # Run in headless mode
|
3482
|
+
chrome_options.add_argument('--no-sandbox')
|
3483
|
+
chrome_options.add_argument('--disable-dev-shm-usage')
|
3484
|
+
chrome_options.add_argument(f"--window-size={image_size}") # Set window size
|
3485
|
+
if ignore_certificate_error:
|
3486
|
+
chrome_options.add_argument('--ignore-certificate-errors') # gnore-certificate-errors
|
3487
|
+
chrome_options.add_argument('--allow-insecure-localhost') # gnore-certificate-errors
|
3488
|
+
# Initialize the Chrome driver
|
3489
|
+
driver = selenium.webdriver.Chrome(options=chrome_options)
|
3490
|
+
rc=False,output_file
|
3491
|
+
try:
|
3492
|
+
# Navigate to the URL
|
3493
|
+
driver.get(url)
|
3494
|
+
|
3495
|
+
#Login to web page
|
3496
|
+
if username and password:
|
3497
|
+
wait = WebDriverWait(driver, 10) # Wait up to 10 seconds
|
3498
|
+
#Search field name for username,password
|
3499
|
+
if auth_fields.get('auth').get('type') == 'id':
|
3500
|
+
by_type=By.ID
|
3501
|
+
else:
|
3502
|
+
by_type=By.NAME
|
3503
|
+
username_field = wait.until(EC.presence_of_element_located((by_type, auth_fields.get('auth').get('name')[0])))
|
3504
|
+
password_field = driver.find_element(by_type, auth_fields.get('auth').get('name')[1])
|
3505
|
+
#login submit
|
3506
|
+
if auth_fields.get('submit',{}).get('type') in ['id','name']:
|
3507
|
+
if auth_fields.get('submit',{}).get('type') == 'id':
|
3508
|
+
by_type=By.ID
|
3509
|
+
else:
|
3510
|
+
by_type=By.NAME
|
3511
|
+
login_button = driver.find_element(by_type, auth_fields.get('submit').get('name'))
|
3512
|
+
else: #button submit type
|
3513
|
+
login_button = driver.find_element(By.XPATH, "//button[@type='submit']")
|
3514
|
+
#put username/password into field
|
3515
|
+
username_field.send_keys(username)
|
3516
|
+
password_field.send_keys(password)
|
3517
|
+
#Login
|
3518
|
+
login_button.click()
|
3519
|
+
|
3520
|
+
if next_do and isinstance(next_do.get('datas'),(list,tuple)):
|
3521
|
+
wait = WebDriverWait(driver, 10) # Wait up to 10 seconds
|
3522
|
+
for do_i in next_do.get('datas'):
|
3523
|
+
if not isinstance(do_i,dict): continue
|
3524
|
+
if do_i.get('type') == 'id':
|
3525
|
+
do_type=By.ID
|
3526
|
+
else:
|
3527
|
+
do_type=By.NAME
|
3528
|
+
user_do_field = wait.until(EC.presence_of_element_located((do_type, do_i.get('name'))))
|
3529
|
+
if do_i.get('click'):
|
3530
|
+
user_do_field.click()
|
3531
|
+
else:
|
3532
|
+
user_do_field.send_keys(do_i.get('data'))
|
3533
|
+
#Submit data
|
3534
|
+
if next_do.get('type') in ['id','name']:
|
3535
|
+
if next_do.get('type') == 'id':
|
3536
|
+
by_type=By.ID
|
3537
|
+
else:
|
3538
|
+
by_type=By.NAME
|
3539
|
+
next_do_button = driver.find_element(by_type, next_do.get('name'))
|
3540
|
+
else: #button submit type
|
3541
|
+
next_do_button = driver.find_element(By.XPATH, "//button[@type='submit']")
|
3542
|
+
next_do_button.click()
|
3543
|
+
|
3544
|
+
# Wait for the page to load
|
3545
|
+
time.sleep(wait_time)
|
3546
|
+
|
3547
|
+
# Capture screenshot
|
3548
|
+
driver.save_screenshot(output_file)
|
3549
|
+
#print(f"Screenshot saved to {output_file}")
|
3550
|
+
rc=True,output_file
|
3551
|
+
except Exception as e:
|
3552
|
+
#print(f"Error capturing screenshot: {str(e)}")
|
3553
|
+
rc=False,str(e)
|
3554
|
+
finally:
|
3555
|
+
# Close the browser
|
3556
|
+
driver.quit()
|
3557
|
+
return rc
|
3558
|
+
|
3450
3559
|
############################################
|
3451
3560
|
#Temporary function map for replacement
|
3452
3561
|
############################################
|
@@ -0,0 +1,6 @@
|
|
1
|
+
kmisc/__init__.py,sha256=uXh4rvX7twUmd9o7TqICr5UCWlAa2i8kzKmpa4BpbSA,150362
|
2
|
+
kmisc-2.1.121.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
|
3
|
+
kmisc-2.1.121.dist-info/METADATA,sha256=L084X4RVPGQGXITXXVrYSswc1agQNfiKVJRdkDu6S3s,5523
|
4
|
+
kmisc-2.1.121.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
5
|
+
kmisc-2.1.121.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
|
6
|
+
kmisc-2.1.121.dist-info/RECORD,,
|
kmisc-2.1.119.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
kmisc/__init__.py,sha256=y5Zhnl1MrphTwpiFDDqb1Wik16xRMSVa-E245qIvgyQ,144993
|
2
|
-
kmisc-2.1.119.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
|
3
|
-
kmisc-2.1.119.dist-info/METADATA,sha256=xSeiDK45vbXDx2QUB1aWT4KhKScIJwPcd683w8ZoiX8,5523
|
4
|
-
kmisc-2.1.119.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
5
|
-
kmisc-2.1.119.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
|
6
|
-
kmisc-2.1.119.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|