From c1d261defb84a8ab35cddb0d46d8993310961d0c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 Apr 2021 13:45:48 +0530 Subject: [PATCH] Fix New Scientist login --- recipes/new_scientist.recipe | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/recipes/new_scientist.recipe b/recipes/new_scientist.recipe index cc4faf6e8b..5f55d013c7 100644 --- a/recipes/new_scientist.recipe +++ b/recipes/new_scientist.recipe @@ -83,22 +83,19 @@ class NewScientist(BasicNewsRecipe): ans = BasicNewsRecipe.get_article_url(self, article) return ans.partition('?')[0] - def is_login_form(self, form): - return "action" in form.attrs and form.attrs['action'] == "/ns-login.php" - def get_browser(self): br = BasicNewsRecipe.get_browser(self) if self.username is not None and self.password is not None: - br.open('http://www.newscientist.com/') - try: - br.open('https://www.newscientist.com/login/') - br.select_form(predicate=self.is_login_form) - br['log'] = self.username - br['pwd'] = self.password - br.submit() - except: - self.log.exception( - 'Unable to locate login form! Switching to free mode.') + def is_login_form(form): + return "action" in form.attrs and form.attrs['action'] == "/login/" + + br.open('https://www.newscientist.com/login/') + br.select_form(predicate=is_login_form) + br['email'] = self.username + br['password'] = self.password + res = br.submit().read() + if b'>Log out<' not in res: + raise ValueError('Failed to log in to New Scientist, check your username and password') return br feeds = [