Skip to content

Commit

Permalink
Merge pull request #418 from bfayers/east-suffolk-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad authored Nov 4, 2023
2 parents d857f52 + eda7093 commit d3744bc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions uk_bin_collection/uk_bin_collection/councils/EastSuffolkCouncil.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Expand Down Expand Up @@ -49,6 +50,9 @@ def parse_data(self, page: str, **kwargs) -> dict:
EC.invisibility_of_element_located((By.CLASS_NAME, "spinner-outer"))
)

# Sometimes the options aren't fully there despite the spinner being gone, wait another 2 seconds.
sleep(2)

# Select address by UPRN
address.select_by_value(user_uprn)

Expand All @@ -57,6 +61,8 @@ def parse_data(self, page: str, **kwargs) -> dict:
EC.invisibility_of_element_located((By.CLASS_NAME, "spinner-outer"))
)

sleep(2)

# Find data table
data_table = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
Expand All @@ -67,18 +73,19 @@ def parse_data(self, page: str, **kwargs) -> dict:
)
)

# Quit Selenium webdriver to release session
driver.quit()


# Make a BS4 object
soup = BeautifulSoup(data_table.get_attribute("innerHTML"), features="html.parser")

# Quit Selenium webdriver to release session
driver.quit()

data = {"bins": []}

rows = soup.find("table").find("tbody").find_all("tr")
for row in rows:
cols = row.find_all("td")
bin_type = cols[2].find_all("span")[1].text
bin_type = cols[2].find_all("span")[1].text.title()
collection_date = cols[3].find_all("span")[1].text
collection_date = datetime.strptime(collection_date, "%d/%m/%Y").strftime(
date_format
Expand Down

0 comments on commit d3744bc

Please sign in to comment.