Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,18 +9,20 @@ def scrape_tariff_data(url):
|
|
| 9 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 10 |
|
| 11 |
# Extract specific elements based on the webpage structure
|
| 12 |
-
#
|
| 13 |
-
tariff_sections = soup.find_all('table')
|
| 14 |
|
| 15 |
data = []
|
| 16 |
for section in tariff_sections:
|
| 17 |
table_rows = section.find_all('tr')
|
| 18 |
for row in table_rows:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
return data # Returns a list of
|
| 24 |
except Exception as e:
|
| 25 |
return f"An error occurred: {e}"
|
| 26 |
|
|
|
|
| 9 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 10 |
|
| 11 |
# Extract specific elements based on the webpage structure
|
| 12 |
+
# Assume tariff data is in <table> tags
|
| 13 |
+
tariff_sections = soup.find_all('table')
|
| 14 |
|
| 15 |
data = []
|
| 16 |
for section in tariff_sections:
|
| 17 |
table_rows = section.find_all('tr')
|
| 18 |
for row in table_rows:
|
| 19 |
+
row_text = ' | '.join(
|
| 20 |
+
col.get_text(strip=True) for col in row.find_all(['th', 'td'])
|
| 21 |
+
)
|
| 22 |
+
if row_text: # Add the row text only if it contains data
|
| 23 |
+
data.append(row_text)
|
| 24 |
|
| 25 |
+
return data # Returns a list of row strings
|
| 26 |
except Exception as e:
|
| 27 |
return f"An error occurred: {e}"
|
| 28 |
|