@@ -52,13 +52,17 @@ def parse_data(self, page: str, **kwargs) -> dict:
52
52
53
53
# Wait for and click cookie button
54
54
cookie_button = wait .until (
55
- EC .element_to_be_clickable (By .CLASS_NAME , "accept-all" )
55
+ EC .element_to_be_clickable (
56
+ (By .CLASS_NAME , "accept-all" )
57
+ )
56
58
)
57
59
cookie_button .click ()
58
60
59
61
# Wait for and find postcode input
60
62
inputElement_pc = wait .until (
61
- EC .presence_of_element_located ((By .ID , "postcode" )
63
+ EC .presence_of_element_located (
64
+ (By .ID , "postcode" )
65
+ )
62
66
)
63
67
64
68
# Enter postcode and submit
@@ -67,7 +71,9 @@ def parse_data(self, page: str, **kwargs) -> dict:
67
71
68
72
# Wait for and find house number input
69
73
selectElement_address = wait .until (
70
- EC .presence_of_element_located (By .ID , "address" )
74
+ EC .presence_of_element_located (
75
+ (By .ID , "address" )
76
+ )
71
77
)
72
78
73
79
dropdown = Select (selectElement_address )
@@ -99,16 +105,16 @@ def parse_data(self, page: str, **kwargs) -> dict:
99
105
# - cell 1 is the date in format eg. 9 September (so no year value 🥲)
100
106
# - cell 2 is the day name, not useful
101
107
# - cell 3 is the bin type eg. "General waste", "Recycling", "Garden waste"
102
- rows = soup .find_all ("tr" , class_ = "govuk-table__row" )
108
+ rows = soup .find ( "tbody" , class_ = "govuk-table__body" ). find_all ("tr" , class_ = "govuk-table__row" )
103
109
104
110
for row in rows :
105
111
bin_type = row .find_all ("td" )[- 1 ].text .strip ()
106
112
107
113
collection_date_string = row .find ('th' ).text .strip ()
108
114
109
115
# sometimes but not always the day is written "22nd" instead of 22 so make sure we get a proper int
110
- collection_date_day = [ int ( i ) for i in collection_date_string .split (' ' ). split ( ) if i .isdigit ()]
111
- collection_date_month_name = collection_date_string .split (' ' )[1 ]
116
+ collection_date_day = "" . join ([ i for i in list ( collection_date_string .split (" " )[ 0 ] ) if i .isdigit ()])
117
+ collection_date_month_name = collection_date_string .split (" " )[1 ]
112
118
113
119
# if we are currently in Oct, Nov, or Dec and the collection month is Jan, Feb, or Mar, let's assume its next year
114
120
if (current_month >= 10 ) and (collection_date_month_name in ["January" , "February" , "March" ]):
@@ -117,7 +123,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
117
123
collection_date_year = current_year
118
124
119
125
collection_date = time .strptime (
120
- f"{ collection_date_day [ 0 ] } { collection_date_month_name } { collection_date_year } " , "%d %B %Y"
126
+ f"{ collection_date_day } { collection_date_month_name } { collection_date_year } " , "%d %B %Y"
121
127
)
122
128
123
129
# Add it to the data
0 commit comments