-
Notifications
You must be signed in to change notification settings - Fork 7
/
scraper.py
50 lines (37 loc) · 1.66 KB
/
scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Create a new instance of the Chrome driver
driver = webdriver.Chrome()
# Navigate to the CPCB website
driver.get("https://app.cpcbccr.com/AQI_India/")
# Wait for the CAPTCHA to be solved
input("Please solve the CAPTCHA and press Enter to continue...")
# Wait for the state dropdown to be clickable
state_dropdown = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "states")))
state_dropdown.click()
# Select the state of Maharashtra
state_option = driver.find_element_by_xpath("//option[contains(text(), 'Maharashtra')]")
state_option.click()
# Wait for the city dropdown to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "cities")))
# Select Mumbai from the city dropdown
city_dropdown = driver.find_element_by_id("cities")
city_dropdown.click()
city_option = driver.find_element_by_xpath("//option[contains(text(), 'Mumbai')]")
city_option.click()
# Click on the date picker
date_picker = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "datepicker")))
date_picker.click()
# Select the start date
start_date = driver.find_element_by_xpath("//td[@data-handler='selectDay']/a[text()='1']")
start_date.click()
# Select the end date
end_date = driver.find_element_by_xpath("//td[@data-handler='selectDay']/a[text()='10']")
end_date.click()
# Click on the Download button
download_button = driver.find_element_by_xpath("//button[contains(text(), 'Download Data')]")
download_button.click()
# Close the webdriver
driver.quit()