CoderHassan commited on
Commit
55a5323
·
verified ·
1 Parent(s): f455440

Update scraper.py

Browse files
Files changed (1) hide show
  1. scraper.py +9 -33
scraper.py CHANGED
@@ -1,37 +1,13 @@
1
  # scraper.py
2
- import urllib3
3
  from bs4 import BeautifulSoup
4
 
5
- def fetch_tariff_from_url(url, load_type):
6
- """Scrape the website to fetch tariff based on load type."""
7
- try:
8
- http = urllib3.PoolManager()
9
- response = http.request("GET", url)
10
- if response.status == 200:
11
- soup = BeautifulSoup(response.data, 'html.parser')
12
- tariff_text = soup.get_text()
13
 
14
- load_type_mapping = {
15
- "Domestic": "A-1 GENERAL SUPPLY TARIFF RESIDENTIAL",
16
- "Commercial": "A-2 GENERAL SUPPLY TARIFF COMMERCIAL",
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