Update extract.py
Browse files- extract.py +39 -1
extract.py
CHANGED
|
@@ -24,4 +24,42 @@ def take_webdata(url):
|
|
| 24 |
if wd:
|
| 25 |
wd.quit()
|
| 26 |
|
| 27 |
-
return Image.open(BytesIO(screenshot)) , page_title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if wd:
|
| 25 |
wd.quit()
|
| 26 |
|
| 27 |
+
return Image.open(BytesIO(screenshot)) , page_title
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_vehicle_info(plate_number: str):
|
| 31 |
+
# Configure headless Chrome
|
| 32 |
+
options = Options()
|
| 33 |
+
options.add_argument("--headless")
|
| 34 |
+
options.add_argument("--disable-gpu")
|
| 35 |
+
options.add_argument("--no-sandbox")
|
| 36 |
+
|
| 37 |
+
# Path to chromedriver (adjust if needed)
|
| 38 |
+
driver = webdriver.Chrome(options=options)
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
# Step 1: Open the site
|
| 42 |
+
driver.get("https://www.jambisamsat.net/infopkb.html")
|
| 43 |
+
time.sleep(2)
|
| 44 |
+
|
| 45 |
+
# Step 2: Find the input and enter plate number
|
| 46 |
+
input_element = driver.find_element(By.NAME, "nopol")
|
| 47 |
+
input_element.send_keys(plate_number)
|
| 48 |
+
|
| 49 |
+
# Step 3: Submit the form
|
| 50 |
+
submit_button = driver.find_element(By.CSS_SELECTOR, 'input[type="submit"]')
|
| 51 |
+
submit_button.click()
|
| 52 |
+
time.sleep(2)
|
| 53 |
+
|
| 54 |
+
driver.implicitly_wait(5)
|
| 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 Exception as e:
|
| 62 |
+
return f"Error occurred: {e}"
|
| 63 |
+
|
| 64 |
+
finally:
|
| 65 |
+
driver.quit()
|