Engineer786 commited on
Commit
86f1015
·
verified ·
1 Parent(s): d053b1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
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
- # Replace 'div' and class with the actual elements where tariff data resides
13
- tariff_sections = soup.find_all('table') # Assume tariff data is in tables
14
 
15
  data = []
16
  for section in tariff_sections:
17
  table_rows = section.find_all('tr')
18
  for row in table_rows:
19
- columns = [col.get_text(strip=True) for col in row.find_all(['th', 'td'])]
20
- if columns:
21
- data.append(columns)
 
 
22
 
23
- return data # Returns a list of rows with tariff data
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