Skip to content

Commit

Permalink
Merge pull request #663 from dp247/660-barnet-council-producing-error
Browse files Browse the repository at this point in the history
Fix: #660 - Barnet Council issues
  • Loading branch information
robbrad authored Apr 15, 2024
2 parents 957ff1e + e486e54 commit 0660fe4
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions uk_bin_collection/uk_bin_collection/councils/BarnetCouncil.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from selenium import webdriver
import time

from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
import re
import time
from datetime import datetime
import json
import requests
from selenium.webdriver.support.ui import WebDriverWait

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
Expand Down Expand Up @@ -78,6 +74,8 @@ def parse_data(self, page: str, **kwargs) -> dict:
page = "https://account.barnet.gov.uk/Forms/Home/Redirector/Index/?id=6a2ac067-3322-46e5-96e4-16c0c214454a&mod=OA&casetype=BAR&formname=BNTCOLDATE"
driver.get(page)

time.sleep(5)

postcode_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, '[aria-label="Postcode"]')
Expand All @@ -93,23 +91,31 @@ def parse_data(self, page: str, **kwargs) -> dict:
)
find_address_button.click()

time.sleep(5)
# Wait for the element with aria-label="Postcode" to be present
time.sleep(15)
# Wait for address box to be visible
select_address_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, '[aria-label="Select your address"]')
(By.ID, 'MainContent_CUSTOM_FIELD_808562d4b07f437ea751317cabd19d9eeaf8742f49cb4f7fa9bef99405b859f2')
)
)

# Select address based
select = Select(select_address_input)
select.select_by_visible_text(user_paon)

addr_label = f"{user_postcode}, {user_paon},"
for addr_option in select.options:
option_name = addr_option.accessible_name[0:len(addr_label)]
if option_name == addr_label:
break
select.select_by_value(addr_option.text)

time.sleep(10)
# Wait for the specified div to be present
target_div_id = "MainContent_CUSTOM_FIELD_808562d4b07f437ea751317cabd19d9ed93a174c32b14f839b65f6abc42d8108_div"
target_div = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, target_div_id))
)

time.sleep(5)
soup = BeautifulSoup(driver.page_source, "html.parser")

# Find the div with the specified id
Expand All @@ -126,8 +132,8 @@ def parse_data(self, page: str, **kwargs) -> dict:
bin_data = {"bins": []}

for bin_div in target_div.find_all(
"div",
{"style": re.compile("background-color:.*; padding-left: 4px;")},
"div",
{"style": re.compile("background-color:.*; padding-left: 4px;")},
):
bin_type = bin_div.find("strong").text.strip()
collection_date_string = (
Expand Down

0 comments on commit 0660fe4

Please sign in to comment.