Spaces:
Sleeping
Sleeping
Update scraper.py
Browse files- scraper.py +9 -33
scraper.py
CHANGED
|
@@ -1,37 +1,13 @@
|
|
| 1 |
# scraper.py
|
| 2 |
-
import
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
if response.status == 200:
|
| 11 |
-
soup = BeautifulSoup(response.data, 'html.parser')
|
| 12 |
-
tariff_text = soup.get_text()
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"Industrial": "B - INDUSTRIAL SUPPLY TARIFFS",
|
| 18 |
-
"Agriculture": "D - AGRICULTURE TARIFF"
|
| 19 |
-
}
|
| 20 |
-
|
| 21 |
-
load_type_label = load_type_mapping.get(load_type, None)
|
| 22 |
-
|
| 23 |
-
if load_type_label:
|
| 24 |
-
start_idx = tariff_text.find(load_type_label)
|
| 25 |
-
if start_idx != -1:
|
| 26 |
-
tariff_section = tariff_text[start_idx:start_idx+1000]
|
| 27 |
-
rates = [float(word) for word in tariff_section.split() if word.replace(".", "").isdigit()]
|
| 28 |
-
if rates:
|
| 29 |
-
return rates[0]
|
| 30 |
-
print(f"No tariff data found for {load_type_label}.")
|
| 31 |
-
else:
|
| 32 |
-
print("Invalid load type selected.")
|
| 33 |
-
else:
|
| 34 |
-
print(f"Failed to fetch data. HTTP Status: {response.status}")
|
| 35 |
-
except Exception as e:
|
| 36 |
-
print(f"Error scraping website: {e}")
|
| 37 |
-
return None
|
|
|
|
| 1 |
# scraper.py
|
| 2 |
+
import requests
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
|
| 5 |
+
def fetch_tariff_data(url):
|
| 6 |
+
response = requests.get(url)
|
| 7 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 8 |
+
tariff_data = parse_tariff_data(soup)
|
| 9 |
+
return tariff_data
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
def parse_tariff_data(soup):
|
| 12 |
+
# Implement based on the specific structure of the HTML page
|
| 13 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|