Skip to content

Commit

Permalink
Merge pull request #1151 from fractos/master
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad authored Jan 10, 2025
2 parents 13f526f + a86253d commit 44605e6
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass

import string

# import the wonderful Beautiful Soup and the URL grabber
class CouncilClass(AbstractGetBinDataClass):
Expand Down Expand Up @@ -37,42 +38,57 @@ def parse_data(self, page: str, **kwargs) -> dict:
# Populate postcode field
inputElement_postcode = driver.find_element(
By.ID,
"ctl00_ContentPlaceHolder1_FF3518TB",
"FF3518-text",
)
inputElement_postcode.send_keys(user_postcode)

# Click search button
driver.find_element(
By.ID,
"ctl00_ContentPlaceHolder1_FF3518BTN",
"FF3518-find",
).click()

# Wait for the 'Select address' dropdown to appear and select option matching UPRN
# Wait for the 'Select address' dropdown to be visible and select option matching UPRN
dropdown = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.ID, "ctl00_ContentPlaceHolder1_FF3518DDL")
EC.visibility_of_element_located(
(By.ID, "FF3518-list")
)
)

# Create a 'Select' for it, then select the matching URPN option
dropdownSelect = Select(dropdown)
dropdownSelect.select_by_value("U" + user_uprn)
found_uprn = False
for o in dropdownSelect.options:
ov = o.get_dom_attribute("value")
if "U" + user_uprn in ov:
dropdownSelect.select_by_value(ov)
found_uprn = True
break

if not found_uprn:
raise Exception("could not find UPRN " + user_uprn + " in list")

# Click submit button
driver.find_element(
By.ID,
"submit-button",
).click()

# Wait for the submit button to appear, then click it to get the collection dates
submit = WebDriverWait(driver, 10).until(
# Wait for the confirmation panel to appear
conf_div = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.ID, "ctl00_ContentPlaceHolder1_btnSubmit")
(By.CLASS_NAME, "ss_confPanel")
)
)
submit.click()

soup = BeautifulSoup(driver.page_source, features="html.parser")

bins_text = soup.find("div", id="ctl00_ContentPlaceHolder1_pnlConfirmation")
bins_text = soup.find("div", id="body-content")

if bins_text:
results = re.findall(
"Your (.*?) bin will next be collected on (\d\d?\/\d\d?\/\d{4})",
bins_text.find("div", {"class": "ss_confPanel"}).get_text(),
r"Your (.*?) bin will next be collected on (\d\d?\/\d\d?\/\d{4})",
bins_text.get_text(),
)
if results:
for result in results:
Expand Down

0 comments on commit 44605e6

Please sign in to comment.