Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adapt to basingstoke site changes #434

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions uk_bin_collection/uk_bin_collection/councils/BasingstokeCouncil.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,21 @@ def parse_data(self, page: str, **kwargs) -> dict:
headers = {
'Accept': '*/*',
'Accept-Language': 'en-GB,en;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://www.basingstoke.gov.uk',
'Pragma': 'no-cache',
'Referer': 'https://www.basingstoke.gov.uk/rte.aspx?id=1270',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Referer': 'https://www.basingstoke.gov.uk/',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'cross-site',
'Sec-Fetch-User': '?1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.188 Safari/537.36',
'X-MicrosoftAjax': 'Delta=true',
'X-Requested-With': 'XMLHttpRequest',
}

params = {
'id': '1270',
}
response = requests.get('https://www.basingstoke.gov.uk/bincollections', cookies=cookies,
headers=headers, verify=False)

data = f'rteelem%24ctl03%24ctl00=rteelem%24ctl03%24ctl01%7Crteelem%24ctl03%24gapAddress%24ctl05&rteelem%24ctl03%24gapAddress%24lstStage2_SearchResults=UPRN%3A{user_uprn}&__EVENTTARGET=rteelem%24ctl03%24gapAddress%24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Btyxc%3D&__ASYNCPOST=true&'
if response.status_code != 200 or response.text == '0|error|500||':
raise SystemError("Error retrieving data! Please try again or raise an issue on GitHub!")

response = requests.post('https://www.basingstoke.gov.uk/rte.aspx', params=params, cookies=cookies,
headers=headers, data=data, verify=False)

if response.status_code != 200:
raise SystemError("Error retrieving data! Please try again or raise an issue on GitHub!")

# Make a BS4 object
soup = BeautifulSoup(response.text, features="html.parser")
Expand Down
Loading