diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-03-27 22:03:30 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-03-27 22:03:30 +0530 |
commit | 7195110a466b0ed14de1b8ee4fa8d7bb79626018 (patch) | |
tree | fef0ce165a5fad64bb0b4e7f49ef68a166ce399b /scrape_ecourtindia_v6/modules/scraper.py | |
parent | f1f43d3448bc879eed55f1e6865c06e646b7eb4a (diff) |
refactor
Diffstat (limited to 'scrape_ecourtindia_v6/modules/scraper.py')
-rw-r--r-- | scrape_ecourtindia_v6/modules/scraper.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/scrape_ecourtindia_v6/modules/scraper.py b/scrape_ecourtindia_v6/modules/scraper.py new file mode 100644 index 0000000..4616763 --- /dev/null +++ b/scrape_ecourtindia_v6/modules/scraper.py @@ -0,0 +1,61 @@ +from time import sleep + +from selenium.webdriver import Firefox +from selenium.webdriver.common.by import By +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.support.select import Select + +class Scraper: + def __init__(self, base_url, headless=True): + options = Options() + if headless: + options.add_argument("--headless") + + self.driver = Firefox(options=options) + self.driver.get(base_url) + + def close_modal(self): + sleep(3) + self.driver.execute_script('closeModel({modal_id:"validateError"})') + sleep(1) + + def select(self, i_d, value): + sleep(1) + element = self.driver.find_element(By.ID, i_d) + select = Select(element) + select.select_by_visible_text(value) + sleep(1) + + def scrape_states(self): + element = self.driver.find_element(By.ID, 'sess_state_code') + options = Select(element).options + states = [ option.text for option in options[1:] ] + print(f'STATES: {states}') + + sleep(0.2) + + return states + + def scrape_districts(self): + element = self.driver.find_element(By.ID, 'sess_dist_code') + options = Select(element).options + districts = [ option.text for option in options[1:] ] + print(f'DISTRICTS: {districts}') + + return districts + + def scrape_complexes(self): + element = self.driver.find_element(By.ID, 'court_complex_code') + options = Select(element).options + complexes = [ option.text for option in options[1:] ] + print(f'COMPLEXES: {complexes}') + + return complexes + + def scrape_establishments(self): + element = self.driver.find_element(By.ID, 'court_est_code') + options = Select(element).options + establishments = [ option.text for option in options[1:] if option.text != '' ] + print(f'ESTABLISHMENTS: {establishments}') + + return establishments |