from selenium import webdriver from selenium.common.exceptions import WebDriverException from PIL import Image from io import BytesIO from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC def take_webdata(url): options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') try: wd = webdriver.Chrome(options=options) wd.set_window_size(1080, 720) # Adjust the window size here wd.get(url) wd.implicitly_wait(5) # Get the page title page_title = wd.title screenshot = wd.get_screenshot_as_png() except WebDriverException as e: return Image.new('RGB', (1, 1)), page_title finally: if wd: wd.quit() return Image.open(BytesIO(screenshot)) , page_title def get_vehicle_info(plate_number: str): # Configure headless Chrome # options = Options() options = webdriver.ChromeOptions() options.add_argument("--headless") options.add_argument("--disable-gpu") options.add_argument("--no-sandbox") # Path to chromedriver (adjust if needed) driver = webdriver.Chrome(options=options) try: driver.get("https://www.jambisamsat.net/infopkb.html") time.sleep(1) # Wait until input box is present WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "no_polisi")) ) # Fill in the plate number input_field = driver.find_element(By.ID, "no_polisi") input_field.clear() input_field.send_keys(plate_number) # Click the submit button by class name submit_button = driver.find_element(By.CSS_SELECTOR, 'button.btn.btn-primary[type="submit"]') submit_button.click() # Wait for the new page to load WebDriverWait(driver, 10).until( EC.url_contains("infopkb.php") ) # # Step 2: Find the input and enter plate number # input_element = driver.find_element(By.NAME, "nopol") # input_element.send_keys(plate_number) # # Step 3: Submit the form # submit_button = driver.find_element(By.CSS_SELECTOR, 'input[type="submit"]') # submit_button.click() # time.sleep(2) driver.implicitly_wait(3) page_title = driver.title screenshot = driver.get_screenshot_as_png() return Image.open(BytesIO(screenshot)) , page_title except WebDriverException as e: return Image.new('RGB', (1, 1)), page_title finally: driver.quit()