Spaces:
Sleeping
Sleeping
Update scraper.py
Browse files- scraper.py +15 -2
scraper.py
CHANGED
|
@@ -9,5 +9,18 @@ def fetch_tariff_data(url):
|
|
| 9 |
return tariff_data
|
| 10 |
|
| 11 |
def parse_tariff_data(soup):
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
return tariff_data
|
| 10 |
|
| 11 |
def parse_tariff_data(soup):
|
| 12 |
+
# Find the table that contains tariff data
|
| 13 |
+
table = soup.find('table')
|
| 14 |
+
tariff_data = []
|
| 15 |
+
|
| 16 |
+
for row in table.find_all('tr')[1:]: # Skipping the header row
|
| 17 |
+
columns = row.find_all('td')
|
| 18 |
+
if len(columns) >= 2: # Ensure there are at least two columns (slab and rate)
|
| 19 |
+
slab = columns[0].text.strip() # Slab details (e.g., 0-50 kWh)
|
| 20 |
+
try:
|
| 21 |
+
rate = float(columns[1].text.strip().replace(',', '').replace('Rs.', '')) # Clean the rate
|
| 22 |
+
except ValueError:
|
| 23 |
+
continue # Skip rows that don’t have a valid rate
|
| 24 |
+
tariff_data.append({'slab': slab, 'rate': rate})
|
| 25 |
+
|
| 26 |
+
return tariff_data
|