Update extract.py
Browse files- extract.py +31 -11
extract.py
CHANGED
@@ -38,28 +38,48 @@ def get_vehicle_info(plate_number: str):
|
|
38 |
driver = webdriver.Chrome(options=options)
|
39 |
|
40 |
try:
|
41 |
-
|
42 |
driver.get("https://www.jambisamsat.net/infopkb.html")
|
43 |
-
time.sleep(
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
-
#
|
50 |
-
submit_button = driver.find_element(By.CSS_SELECTOR, '
|
51 |
submit_button.click()
|
52 |
-
time.sleep(2)
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
page_title = driver.title
|
57 |
screenshot = driver.get_screenshot_as_png()
|
58 |
|
59 |
return Image.open(BytesIO(screenshot)) , page_title
|
60 |
|
61 |
-
except
|
62 |
-
return
|
63 |
|
64 |
finally:
|
65 |
driver.quit()
|
|
|
38 |
driver = webdriver.Chrome(options=options)
|
39 |
|
40 |
try:
|
41 |
+
|
42 |
driver.get("https://www.jambisamsat.net/infopkb.html")
|
43 |
+
time.sleep(1)
|
44 |
+
|
45 |
+
|
46 |
+
# Wait until input box is present
|
47 |
+
WebDriverWait(driver, 10).until(
|
48 |
+
EC.presence_of_element_located((By.ID, "no_polisi"))
|
49 |
+
)
|
50 |
|
51 |
+
# Fill in the plate number
|
52 |
+
input_field = driver.find_element(By.ID, "no_polisi")
|
53 |
+
input_field.clear()
|
54 |
+
input_field.send_keys(plate_number)
|
55 |
|
56 |
+
# Click the submit button by class name
|
57 |
+
submit_button = driver.find_element(By.CSS_SELECTOR, 'button.btn.btn-primary[type="submit"]')
|
58 |
submit_button.click()
|
|
|
59 |
|
60 |
+
# Wait for the new page to load
|
61 |
+
WebDriverWait(driver, 10).until(
|
62 |
+
EC.url_contains("infopkb.php")
|
63 |
+
)
|
64 |
+
|
65 |
+
# # Step 2: Find the input and enter plate number
|
66 |
+
# input_element = driver.find_element(By.NAME, "nopol")
|
67 |
+
# input_element.send_keys(plate_number)
|
68 |
+
|
69 |
+
# # Step 3: Submit the form
|
70 |
+
# submit_button = driver.find_element(By.CSS_SELECTOR, 'input[type="submit"]')
|
71 |
+
# submit_button.click()
|
72 |
+
# time.sleep(2)
|
73 |
+
|
74 |
+
driver.implicitly_wait(3)
|
75 |
|
76 |
page_title = driver.title
|
77 |
screenshot = driver.get_screenshot_as_png()
|
78 |
|
79 |
return Image.open(BytesIO(screenshot)) , page_title
|
80 |
|
81 |
+
except WebDriverException as e:
|
82 |
+
return Image.new('RGB', (1, 1)), page_title
|
83 |
|
84 |
finally:
|
85 |
driver.quit()
|