Skip to content

Commit 4a2014b

Browse files
fix: parsing error in BH selenium
1 parent 41f6f3d commit 4a2014b

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

uk_bin_collection/uk_bin_collection/councils/CheltenhamBoroughCouncil.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,39 @@ def parse_data(self, page: str, **kwargs: str) -> dict[str, list[dict[str, str]]
245245
# extract table body
246246
for row in table.find_all("tr")[1:]:
247247
if row.find_all("td")[1].text.strip() == "Normal collection day":
248-
bh_dict[
249-
parse(
250-
row.find_all("td")[0].text.strip(),
251-
dayfirst=True,
252-
fuzzy=True,
253-
).date()
254-
] = parse(
255-
row.find_all("td")[0].text.strip(), dayfirst=True, fuzzy=True
256-
).date()
248+
try:
249+
# Check for normal collection day (no change)
250+
if row.find_all("td")[0].text.strip() == "Normal collection":
251+
continue
252+
else:
253+
bh_dict[
254+
parse(
255+
row.find_all("td")[0].text.strip(),
256+
dayfirst=True,
257+
fuzzy=True,
258+
).date()
259+
] = parse(
260+
row.find_all("td")[0].text.strip(), dayfirst=True, fuzzy=True
261+
).date()
262+
except:
263+
continue
257264
else:
258-
bh_dict[
259-
parse(
260-
row.find_all("td")[0].text.strip(),
261-
dayfirst=True,
262-
fuzzy=True,
263-
).date()
264-
] = parse(
265-
row.find_all("td")[1].text.strip(), dayfirst=True, fuzzy=True
266-
).date()
265+
try:
266+
# Check for normal collection day (no change)
267+
if row.find_all("td")[1].text.strip() == "Normal collection":
268+
continue
269+
else:
270+
bh_dict[
271+
parse(
272+
row.find_all("td")[0].text.strip(),
273+
dayfirst=True,
274+
fuzzy=True,
275+
).date()
276+
] = parse(
277+
row.find_all("td")[1].text.strip(), dayfirst=True, fuzzy=True
278+
).date()
279+
except:
280+
continue
267281

268282
for refuse_date in refuse_dates:
269283
collection_date = (datetime.strptime(refuse_date, "%d/%m/%Y") + timedelta(

0 commit comments

Comments
 (0)