kmisc 2.1.120__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 CHANGED
@@ -3448,7 +3448,16 @@ def Upper(src,default='org'):
3448
3448
  if default in ['org',{'org'}]: return src
3449
3449
  return default
3450
3450
 
3451
- def web_capture(url,output_file,image_size='1920,1080',wait_time=3):
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
+
3452
3461
  if isinstance(image_size,str):
3453
3462
  if 'x' in image_size:
3454
3463
  image_size=image_size.split('x')
@@ -3465,18 +3474,73 @@ def web_capture(url,output_file,image_size='1920,1080',wait_time=3):
3465
3474
  else:
3466
3475
  # Configure Chrome options for headless mode
3467
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
3468
3480
  chrome_options = Options()
3469
3481
  chrome_options.add_argument('--headless') # Run in headless mode
3470
3482
  chrome_options.add_argument('--no-sandbox')
3471
3483
  chrome_options.add_argument('--disable-dev-shm-usage')
3472
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
3473
3488
  # Initialize the Chrome driver
3474
3489
  driver = selenium.webdriver.Chrome(options=chrome_options)
3475
3490
  rc=False,output_file
3476
3491
  try:
3477
3492
  # Navigate to the URL
3478
3493
  driver.get(url)
3479
-
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
+
3480
3544
  # Wait for the page to load
3481
3545
  time.sleep(wait_time)
3482
3546
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.120
3
+ Version: 2.1.121
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -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,,
@@ -1,6 +0,0 @@
1
- kmisc/__init__.py,sha256=Qohn7dgINzBWEjZdl2wfKfd8BA1hlRU3aJqTrZODRok,146663
2
- kmisc-2.1.120.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
- kmisc-2.1.120.dist-info/METADATA,sha256=hdsc0wTLXtmnsiy-gE1iHYnABkJwT1fy3oGbH44tbm8,5523
4
- kmisc-2.1.120.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
5
- kmisc-2.1.120.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
- kmisc-2.1.120.dist-info/RECORD,,