@@ -72,7 +72,9 @@ def parse_data(self, page: str, **kwargs) -> dict:
72
72
break
73
73
74
74
if not found :
75
- raise Exception (f"Address containing '{ user_paon } ' not found in dropdown options" )
75
+ raise Exception (
76
+ f"Address containing '{ user_paon } ' not found in dropdown options"
77
+ )
76
78
77
79
submit_btn = wait .until (
78
80
EC .presence_of_element_located (
@@ -84,7 +86,7 @@ def parse_data(self, page: str, **kwargs) -> dict:
84
86
85
87
results = wait .until (
86
88
EC .presence_of_element_located (
87
- (By .XPATH , f'//span [contains(@class,"collection-sub ")]' )
89
+ (By .XPATH , f'//div [contains(@class,"mx-name-listView1 ")]' )
88
90
)
89
91
)
90
92
@@ -96,44 +98,21 @@ def parse_data(self, page: str, **kwargs) -> dict:
96
98
current_date = datetime .now ()
97
99
98
100
# Find all elements with class starting with 'mx-name-index-'
99
- bins = soup .find_all (class_ = lambda x : x and x .startswith ("mx-name-index-" ))
101
+ bin_view = soup .find (class_ = "mx-name-listView1" )
102
+ bins = bin_view .find_all (
103
+ class_ = lambda x : x and x .startswith ("mx-name-index-" )
104
+ )
100
105
101
106
for bin_item in bins :
102
- bin_type = bin_item .find (class_ = "collection-main" ).text .strip ()
103
- day_of_week_elements = bin_item .find_all (class_ = "collection-header" )
104
- bin_date = None
105
-
106
- for elem in day_of_week_elements :
107
- if (
108
- elem .text .strip () != bin_type
109
- ): # Avoid taking the bin type as the date
110
- next_sibling = elem .find_next_sibling ()
111
- if next_sibling :
112
- bin_date_str = next_sibling .text .strip ()
113
- try :
114
- # Try parsing the date string in the format 'dd Month' (e.g., '30 Dec', '5 January')
115
- bin_date = datetime .strptime (bin_date_str , "%d %b" )
116
- except ValueError :
117
- try :
118
- # If the above format fails, try 'dd MonthName' (e.g., '30 December', '5 January')
119
- bin_date = datetime .strptime (bin_date_str , "%d %B" )
120
- except ValueError :
121
- pass
122
-
123
- if bin_date :
124
- # Set the year based on the logic provided
125
- if bin_date .month < current_date .month :
126
- bin_date = bin_date .replace (
127
- year = current_date .year + 1
128
- )
129
- else :
130
- bin_date = bin_date .replace (year = current_date .year )
131
- # Format the date to the desired format
132
- bin_date = bin_date .strftime ("%d/%m/%Y" )
133
- break
107
+ bin_type = bin_item .find (class_ = "mx-name-text31" ).text .strip ()
108
+
109
+ bin_date_str = bin_item .find (class_ = "mx-name-text29" ).text .strip ()
110
+
111
+ bin_date = datetime .strptime (bin_date_str , "%d %B %Y" )
112
+ bin_date = bin_date .strftime (date_format )
113
+
134
114
dict_data = {"type" : bin_type , "collectionDate" : bin_date }
135
115
data ["bins" ].append (dict_data )
136
- print (data )
137
116
except Exception as e :
138
117
# Here you can log the exception if needed
139
118
print (f"An error occurred: { e } " )
0 commit comments