From d81eefa7f3be4816b1e53bf01783d5df73fd6509 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Fri, 13 May 2022 11:04:25 -0500 Subject: [PATCH] AO3: use new form helper so this shouldn't break again if fields change --- sites/ao3.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/sites/ao3.py b/sites/ao3.py index 9c84e78..10b8441 100644 --- a/sites/ao3.py +++ b/sites/ao3.py @@ -24,19 +24,13 @@ class ArchiveOfOurOwn(Site): with requests_cache.disabled(): login = self.session.get('https://archiveofourown.org/users/login') soup = BeautifulSoup(login.text, 'html5lib') - form = soup.find(id='new_user') - post = { - 'user[login]': login_details[0], - 'user[password]': login_details[1], - # standard fields: - 'user[remember_me]': '1', - 'authenticity_token': form.find(attrs={'name': 'authenticity_token'})['value'], - 'commit': 'Log in', - } + post, action, method = self._form_data(soup.find(id='new_user')) + post['user[login]'] = login_details[0] + post['user[password]'] = login_details[1] # I feel the session *should* handle this cookies bit for me. But # it doesn't. And I don't know why. self.session.post( - self._join_url(login.url, str(form.get('action'))), + self._join_url(login.url, action), data=post, cookies=login.cookies ) logger.info("Logged in as %s", login_details[0])